I've met a scenario:
save
or update
some data in a target table by hibernateinsert
or update
operations of the target tableselect
out this record by hibernateBut I find that the fields which have been modified by the trigger are not really fetched out. Is this related with transactions commit of Hibernate (flush() has already be called) or Hibernate cache? thanks.
You can map properties as generated values. These values always come from the database and can't be stored. Hibernate automatically loads these values in a subsequent query after inserting or updating the database.
This can be caused by both the first (session) or second (e.g. ehcache) caches. To re-read the entity, you'll need to call session.refresh().
From hibernate docs (at the bottom of the section)
It is possible to re-load an object and all its collections at any time, using the refresh() method. This is useful when database triggers are used to initialize some of the properties of the object.
sess.save(cat);
sess.flush(); //force the SQL INSERT
sess.refresh(cat); //re-read the state (after the trigger executes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With