-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Huge performance difference: EntityManager and Session query
PostPosted: Thu Jul 03, 2008 3:34 pm 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
(Reposted from Users forum)....

Hi,
I am doing some experimentation with Hibernate and EJB3 and have noticed if I run a simple query using entityManager.createQuery() it is several times slower than a standard hibernate session.createQuery() executing the same query string.

I am timing the actual hibernate call itself (not serialisation etc.) so i can't explain the differences....
--------------------------------------
long starMillis = System.currentTimeMillis();
List<Job> temp = entityManager.createQuery("from JobBean WHERE completionDate IS NULL AND isClosed = false AND deleted = false ORDER BY id").getResultList();
long endMillis = System.currentTimeMillis();

log.info("Adding " + temp.size() + " jobs in " + (endMillis-starMillis) + "mS");
--------------------------------------

and

--------------------------------------
long starMillis = System.currentTimeMillis();
List<Job> temp = session.createQuery("from JobBean WHERE completionDate IS NULL AND isClosed = false AND deleted = false ORDER BY id").getResultList();
long endMillis = System.currentTimeMillis();

log.info("Adding " + temp.size() + " jobs in " + (endMillis-starMillis) + "mS");
--------------------------------------

The EJB is running in GlassfishV2 and the hibernate session version is running in a JSE application. The PU and hibernate.cfg.xml have the same parameters etc..

The Session bean/EntityManager takes 24 seconds to retrieve 3216 jobs and the standard JSE/session takes a mere 6.7 seconds - so the difference is nontrivial.

The only other change asside from the EntityManager Vs raw hibernate session is the EntityManager entities utilise interfaces and make use of the @Target(class) annotation to identify the implementation class - asside from that the models are the same.

Still confused as to what is causing the performance problem....

Any help and pointers appreciated.

Has anyone experienced anything similar?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 5:44 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
1) could you try removing the @Target to make them really the same?

2)are you sure the same transactions are used?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 05, 2008 4:01 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
OK, I haven't removed the @Target annotation yet, cos thats a lot of work... but I created a standard hibernate session within the EJB, so know I run the same query via the app server managed EntityManager and via a hibernate session created from a standalone hiberbate.cfg.xml....


EntityManager query time = 26.6 seconds
Hibernate session query time = 12.3 seconds

So, they are both slower than the same code run in JSE, and the EntityManager is still considerably slower than a standard hibernate session.

Still more investigation needed


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.