java - catch oracle sequence and set it to another field in JPA -


an enity bean has generated sequence id (oracle primary key). need catch sequence somehow on persist , set field. example:

class entity {     @id long id;     @column long parentid; } 

the idea make parentid same id generated oracle if empty. example:

@prepersist void prepersist() {     if (parentid = 0) parentid = id; // id not yet generated } 

currently use db trigger achieve this, can done in jpa (preferably without hibernate specific classes)?

when persist entity in jpa, our entity object become managed, , @ point should have id populated. pre-persist, not post-persist, not have id populated.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -