-->
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: createQuery help needed
PostPosted: Sun May 20, 2007 1:30 am 
Newbie

Joined: Sat May 19, 2007 10:50 pm
Posts: 4
Hi,

Using the following query
Query q = session.createQuery("from LocationInfo where path like %"+des+"%" );

but hibernate is throwing exception saying that

unexpected char: '%'

can any body help me, how to use that % functionality with in the creatQuery.

Thanks
Badri


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 5:50 am 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
you are simply missing the single quotes:

Code:
Query q = session.createQuery("from LocationInfo where path like '%"+des+"%'" );


page 154 hibernate_reference.pdf


Please rate if it helps


Top
 Profile  
 
 Post subject: Re: createQuery help needed
PostPosted: Sun May 20, 2007 1:50 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 3:35 pm
Posts: 24
Location: Buenos Aires, Argentina
nath wrote:
Using the following query
Query q = session.createQuery("from LocationInfo where path like %"+des+"%" );

but hibernate is throwing exception saying that

unexpected char: '%'

can any body help me, how to use that % functionality with in the creatQuery.


Besides the missing single quotes, you shoud use parameters for this. Like this:

Query q = session.createQuery("from LocationInfo where path like :des" );
q.setParameter("des", "%" + des + "%");

With this you are protected from single quotes appearing in the string, and the DB can do a better job caching the query plan. And with this you no longer need single quotes.

Rate if this helps =).


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.