Hibernate session.refresh() method

Hibernate session.refresh() method

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.save(cat);
session.flush(); //force the SQL INSERT
session.refresh(cat); //re-read the state (after the trigger executes);









Related Tutorials/Questions & Answers:

Ads