-->
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: createQuery like statement
PostPosted: Fri Jul 03, 2009 1:51 am 
Beginner
Beginner

Joined: Wed May 10, 2006 9:43 pm
Posts: 30
Location: Australia
Hi everyone,

I would like to extend the below query to check if product.id is like productSearchString. I have added an AND although an error exists. Haven't been able to find the syntax to support this, is it possible?

Query query = session.createQuery(
"from Product product where product.nameOfProductOrService like '%" + searchString + "%'");

Please post a response if you can help.

Thanks, Alyssa.


Top
 Profile  
 
 Post subject: Re: createQuery like statement
PostPosted: Fri Jul 03, 2009 3:21 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Try this:

Code:
Query query = session.createQuery(
"from Product product where product.nameOfProductOrService like :str").setString("str", "%" + searchString + "%");


It is not a good idea to construct SQL with parameters using concatenate.
Always try to use some of the Query.setParameter methods to set query parameters.

https://www.hibernate.org/hib_docs/v3/api/

You can also try to use the criterias. http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycriteria.html


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.