performance issue in find() method after migration to Hibernate 4.0 from OpenJPA 1.2

338 views Asked by At

I migrate from OpenJPA 1.2 to Hiberante 4.0
I'm using TimesTen DB

I'm doing a native query to get id's of object's that I need , and then perform find on each on of them. In OpenJPA instead of find I used findCache() method and if it return null I use the find() method , In hibernate I used only the find() method.

I performed this operation on the same DB.

after running couple of test I saw that the performance of OpenJPA is far better.

I printed the statistics of hibernate session ( after querying and finding the same object's) and saw that the hit\miss count to the first level cache is always 0. while the OpenJPA is clearly reaching it's cache by fetching object's with the findCache method.

How can I improve the performance of find in Hibernate ? I suspect it referred to the difference in the first level cache implementation of this tools.

another fact: I use the same EntityManager for the application run time ( I need to minimize the cost of creating of an EntityManager - my app is soft real time )

thanks.

2

There are 2 answers

3
drone.ah On

Firstly, why don't you just retrieve the full objects instead of the id. One select statement to retrieve a number of objects is many magnitude times faster than retrieving each item individually.

Secondly, you likely need a second level cache for hibernate. The first level cache is mostly applicable within each session.

0
Emmanuel Bernard On

The first level cache in Hibernate corresponds to the session. So if the session has not yet loaded a given object, it will be a miss. You need to enable second level cache to be able to cache an object by id across sessions.

Check out the reference documentation for more info http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#performance-cache