-->
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.  [ 2 posts ] 
Author Message
 Post subject: Does Hibernate take indexes into account?
PostPosted: Fri Jul 12, 2013 4:33 am 
Newbie

Joined: Thu May 03, 2012 4:01 pm
Posts: 5
Hello everyone, I was wondering something I just noticed.

I have this query in hibernate:

Code:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, -12);
Query q = entityManager().createQuery("SELECT COUNT(o) FROM BuyRespPraomp o where insertTimestamp > :date ", Long.class);
q.setParameter("date", cal.getTime());
return (Long) q.getSingleResult();


The field insertTimestamp is indexed on the database.
Now, what I noticed is that this query takes a couple milliseconds if I execute it from say Toad, and as much as five seconds if I run it from my application using Hibernate.
Am I being silly and missing something obvious here?

Thanks as always,
TD


Top
 Profile  
 
 Post subject: Re: Does Hibernate take indexes into account?
PostPosted: Fri Jul 19, 2013 6:46 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
Hibernate does not take indexes unless you don't specify it.
More info : http://www.znetdevelopment.com/blogs/2009/10/07/using-use-index-with-hibernatemysql/.

And i dont think you are missing anything in your code here.

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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