-->
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.  [ 7 posts ] 
Author Message
 Post subject: Huge performance difference: EntityManager and Session query
PostPosted: Wed Jul 02, 2008 6:35 pm 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
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 47.6 seconds to retrieve 3216 jobs and the standard JSE/session takes a mere 6.7 seconds - so the difference is nontrivial.


Has anyone experienced anything similar?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 03, 2008 4:19 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Just a quick update...

I tweaksed the app server settings and changed the driver to the PooledConnection variant (I'm using PostgreSQL).

The EntityManager timings are now around 22-24 seconds, still a very large difference.

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 appreciatted.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 03, 2008 5:34 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Just a quick update...

I tweaksed the app server settings and changed the driver to the PooledConnection variant (I'm using PostgreSQL).

The EntityManager timings are now around 22-24 seconds, still a very large difference.

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 appreciatted.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 03, 2008 5:35 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Just a quick update...

I tweaksed the app server settings and changed the driver to the PooledConnection variant (I'm using PostgreSQL).

The EntityManager timings are now around 22-24 seconds, still a very large difference.

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 appreciatted.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:31 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, I can't provide any pointers per se, but I did want to say that I'm finding you posts interesting. Keep us informed!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 05, 2008 3:57 am 
Newbie

Joined: Wed Jul 02, 2008 6:17 pm
Posts: 11
Switching over to the similiar thread I have under the EntityManager et al forum:

http://forum.hibernate.org/viewtopic.php?t=988354


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 05, 2008 2:15 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 8:18 am
Posts: 31
Entitymanager also run in JSE application. Try query with EntityManager but without using any ejb container. I mean try it in jse application and compare the results.

_________________
amer sohail


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.