Friday, April 3, 2009

Hibernate load vs get


In my current project where we are using spring-hibernate we faced an issue where at certain times stale objects were being manipulated when tested on concurrent access. When doing throught the specs we were able to nail down the issue which was basically the way the methods load and get works in hibernate. According to the specs, the load method populated that respective entity object with cached results where as get method fetched it from the database.
 
So when ever you want to do a batch operation as i see it, its always better to use load method to achieve better performance where as you should use the get method if you are regularly updating and recovering data from a particular table.
 
If your a EJB 3 EntityManager fan then this same can be achieved through the getReference() method which is the same as the load method in hibernate.


2 comments:

Anonymous said...

Thanks a lot for posting the message.It was quite useful.

Dinuka Arseculeratne said...

Glad i could help

Post a Comment

 
;