-->
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: hql like % not performant enough
PostPosted: Thu Mar 02, 2006 8:33 am 
Newbie

Joined: Wed Mar 01, 2006 4:14 am
Posts: 16
in my company we have table of 10, 100 thousands and even millions of records

the environment is Oracle 10/Hibernate 3.1/Spring 1.2/JSF something

if I use setString("studiejaarCode", studiejaarCode) instead of
setString("studiejaarCode", studiejaarCode +"%") I do not get results at all

any ways this method is very slow


low perfomance
/////////////////////////////////////////
final String sql =
"select opleidingsonderdeel " +
"from Opleidingsonderdeel opleidingsonderdeel, OpleidingsonderdeelLink opleidingsonderdeelLink, Component component " +
"where component.componentCode like :studiejaarCode " +
"and opleidingsonderdeel.opleidingsonderdeelCode=opleidingsonderdeelLink.compositeKey.opleidingsonderdeelCode " +
"and opleidingsonderdeelLink.compositeKey.onderdeelCode=component.componentCode";

final List results =
getHibernateTemplate().getSessionFactory().openSession()
.createQuery(sql)
.setString("studiejaarCode", studiejaarCode +"%").list();
/////////////////////////////////////////


the other method is when I insert the variable directly into the hql and gives a good performance in comparison to the first method but in the reference and Hibernate in action is stated that this aint a good practice

high perfomance
/////////////////////////////////////////
final String sql =
"select opleidingsonderdeel " +
"from Opleidingsonderdeel opleidingsonderdeel, OpleidingsonderdeelLink opleidingsonderdeelLink, Component component " +
"where component.componentCode like '" + studiejaarCode + "%' " +
"and opleidingsonderdeel.opleidingsonderdeelCode=opleidingsonderdeelLink.compositeKey.opleidingsonderdeelCode " +
"and opleidingsonderdeelLink.compositeKey.onderdeelCode=component.componentCode";

final List results =
getHibernateTemplate().getSessionFactory().openSession()
.createQuery(sql).list();
/////////////////////////////////////////



has anyone have had this problem too; is this a problem in Hibernate or in Oracle


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 9:15 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello,

where did you find that like 'text%' is not recommended. I think it is the only way. If it is not fast enough for example when searching in text strings with multiple words than you consider too use full text indexing

regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 9:28 am 
Newbie

Joined: Wed Mar 01, 2006 4:14 am
Posts: 16
no putting your variables directly into the sql is not recommended (opposed to binding them afterwards)


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.