-->
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.  [ 6 posts ] 
Author Message
 Post subject: LIKE condition in HQL
PostPosted: Fri May 18, 2007 11:00 am 
Newbie

Joined: Thu May 17, 2007 10:51 am
Posts: 16
Hi everybody,

I have an SQL query like

select cu1.last_name from content_user cu1
where lower(cu1.last_name) like lower('%gupta%');


. How can I convert this into HQL query like the following


select cu from com.manic.ContentUser cu where cu.lastName = lower(:lastName).......


Here I want to use the "like" condition for %guta% format.




THanks in advance

_________________
Manic


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 11:41 am 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
sessionobject .createCriteria(com.manic.ContentUser.class)
.add(Expression.like("firstName", "%guta%"))


Top
 Profile  
 
 Post subject: Re : Like condition in HQL
PostPosted: Fri May 18, 2007 11:59 am 
Newbie

Joined: Thu May 17, 2007 10:51 am
Posts: 16
Hey,

If I want the firstName from 2 CLasses then how can I do that. For example I have 2 POJO ContentUser cu and ContentUserRole cur


I need to do like this

cu.firstName like ('%guta%') and cur.firstName like('%guta%'). For this scenario how can i do the criteria.



Thanks

_________________
Manic


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 12:20 pm 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
[quote]
cu.firstName like ('%guta%') and cur.firstName like('%guta%'). [/quote]

select first name from cu.firstName from cu table1, cu table2 where

cu.firstName like :parameter and cur.firstName like :parameter

wherein u pass the parameter to be %gupta% from ur DAO.


Top
 Profile  
 
 Post subject: Re: LIKE condition in HQL
PostPosted: Sat May 19, 2007 12:20 am 
Newbie

Joined: Mon Dec 11, 2006 12:54 am
Posts: 14
mmanickaraj wrote:
Hi everybody,

I have an SQL query like

select cu1.last_name from content_user cu1
where lower(cu1.last_name) like lower('%gupta%');


. How can I convert this into HQL query like the following


select cu from com.manic.ContentUser cu where cu.lastName = lower(:lastName).......


Here I want to use the "like" condition for %guta% format.




THanks in advance


Hi,

You can use something like following HQL query :

select cu.last_name from com.manic.ContentUser as cu where lcase(cu.last_name ) like '%gupta%'


Top
 Profile  
 
 Post subject: Thanks satsranchuser
PostPosted: Sat May 19, 2007 12:42 am 
Newbie

Joined: Thu May 17, 2007 10:51 am
Posts: 16
Hey satsranchuser,
I followed your suggestion , it's doing god man.. Thanks very much..

_________________
Manic


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