-->
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.  [ 6 posts ] 
Author Message
 Post subject: Is there a performace difference here?
PostPosted: Thu Nov 02, 2006 5:23 pm 
Newbie

Joined: Mon Oct 17, 2005 2:55 pm
Posts: 5
Location: Toronto, Canada
Hi, I'm using Hibernate 2.1.7 now, and wonder the uses below make really a difference in performance. Thanks a lot for the answer in advance.

1. sesssion.get(MyData.class, new Long(getId()))

2. session.createCriteria(MyData.class).add(Expression.eq("id", getId())).uniqueResult()

BK


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 4:36 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
I doubt that there is a big difference in the performance.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 10:03 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"sesssion.get" must be better, it must execute SQL generated on startup, "session.createCriteria" will build it for every call.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 11:23 am 
Newbie

Joined: Mon Oct 17, 2005 2:55 pm
Posts: 5
Location: Toronto, Canada
I understand the second case can include caching control as follows. Can this be a good advantage then? I'm assuming get() cannot provide query result caching.

session.createCriteria(MyData.class).add(Expression.eq("id", getId())).setCacheable(true).uniqueResult()


Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 11:52 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"get" and "load" must cache result if cache is enabled in class mapping (see "<cache/>" tag)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 12:21 pm 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
if caching is enabled get will first look into the cache and then into db if it does not find in entity cache. criteria will fecth it from querycache if query cache is enabled else it will be slow as it will have to make a db call.So there is difinitely a performance issue.
hope this helps and if so please do rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.