-->
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: Criteria for for 'startswith' query?
PostPosted: Sun Nov 27, 2005 9:43 pm 
Newbie

Joined: Thu Sep 08, 2005 12:07 pm
Posts: 6
Hello,
I am trying to optimize a query that returns names from a table where the lastName starts with a certain letter.

Currently, I am using the following:

Criteria criteria = HibernateUtil.getSession().createCriteria(Contact.class)
.createAlias("contactInfo", "c")
.add(Expression.ilike("c.lastName", searchLetter + "%"))
.addOrder(Order.asc("c.lastName"));

return criteria.list();

which is working, but is slow. I have an index on the ContactInfo table on lastName column, which helps, but I'm hoping for better...

I am using a PostgreSQL db, for which I am fairly new at. Is there a better way?
Thanks for any Help!
Eric

_________________
Eric Hansen


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 27, 2005 11:29 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
I'm not sure if there's a way around your "startswith" query. What you are doing here is exactyly what anyone would do even with or w/o Hibernate.

Typically queries like these tend to be slower and you might want to look at a query plan of sorts on your SQL (not sure of Post Gre SQL supports that).


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.