6

I've met a scenario:

  1. save or update some data in a target table by hibernate
  2. there is a trigger on the target table which will be executed before insert or update operations of the target table
  3. select out this record 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.

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

5

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.