views:

38

answers:

3

i need to intercept post save for an entity in hibernate, but all what i found was on save, which is dealing with the entity before being saved, and there's a postFlush method which return a huge lazy iterator, that i can't understand how to use it, please suggest me a way to catch entity after hibernate save or update,

Regards,

A: 

Try the javax.persistance.PostPersist annotation:

@PostPersist
private void postPersist()
{
    // do stuff
}
Coronatus
The OP didn't say he used JPA, though.
seanizer
That's right, am using hibernate not entity manger (JPA) implementation
Amr Faisal
A: 

Well I guess you are looking for the SaveOrUpdateEventListener interface.

(Here is a reference of the Hibernate event system.)

seanizer
+1  A: 

postFlush is what you want. The iterator will let you loop through all of the entities that were inserted or updated. It gets called after the sql has executed in the database.

Brian Deterling
am going through it right now, but it perform a strange behavior, as sometime the object from this array isn't updated with latest changes in DB
Amr Faisal