Hibernate session.refresh() method



Share on Google+Share on Google+

Rahul Dev
Hibernate session.refresh() method
1 Answer(s)      6 years and 10 months ago
Posted in : Hibernate

What is session.refresh() in hibernate?

View Answers

October 26, 2010 at 4:16 PM

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.

For Example - Triger on catname coulmn. Trigger is updating hitcount coulmn in the same Cat Table. When Insert data into Cat TABLE trigger update hit_count coulmn to 1. session.refresh() reload all the data. No nned again to select call.

session.flush(); //force the SQL INSERT
session.refresh(cat); //re-read the state (after the trigger executes);