I've met a scenario:
save
orupdate
some data in a target table by hibernate- there is a trigger on the target table which will be executed before
insert
orupdate
operations of the target table select
out this reco开发者_运维问答rd by hibernate
But 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)
精彩评论