-->
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.  [ 4 posts ] 
Author Message
 Post subject: What about a LIKE Statement??
PostPosted: Fri Jul 28, 2006 2:08 am 
Newbie

Joined: Tue Jul 25, 2006 10:10 am
Posts: 4
Location: Germany
Good morning!

I am using nHibernate to persist an object that contains a property of the DateTime type and I use to build a query to select them. Can anyone of you tell me whether it is possible to compare an incoming string (contains a date typed in by the user) and the DateTime values saved in my database table using a LIKE statement?

I already tried statements like " where Date LIKE '*<value>*' " or " where Date LIKE '%<value>%' "...
Every query was executed by nHibernate. No errors... But there were no results.

Is it just a simple mistake in my statement or isn't it possible to compare DateTime's and strings with LIKE?

I thank you very much in advance.

Monty


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:24 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Isntead of doing this in HQL you can use the "Expression.like()" in the "org.hibernate.criterion" package instead.


Top
 Profile  
 
 Post subject: Hah....
PostPosted: Fri Jul 28, 2006 3:30 am 
Newbie

Joined: Tue Jul 25, 2006 10:10 am
Posts: 4
Location: Germany
I made it... still using HQL...

I changed the type of the incoming value to object (value is something like "26.07.2006 00:00:01") and compare the values stored in my database table like this:

where Date >= value AND Date < value + 1 day

and it works fine.

But I thank you very much anyway... :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 10:26 am 
Newbie

Joined: Sat Aug 13, 2005 2:35 pm
Posts: 4
hi pals!!!

This is a way to do LIKE in a hql query..

Query q = em.createQuery("select new s from Student as s where s.name like :x");
q.setParameter("x",name+"%");

Notice that here I'm using EntityManager, but the same idea also works for Session, but the method to set the variable "x" is setString, if I'm not wrong

I don't know if it'll help, but there it is...


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