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: Reg. HQL query
PostPosted: Wed Jan 03, 2007 7:54 am 
Newbie

Joined: Wed Oct 11, 2006 2:46 am
Posts: 3
Hi,
I am new to Hibernate.
I want all users'names not starting with "Mu%". This is my code.

Query q = session.createQuery("from Test u where u.name like \"Mu%\" ");
List result = q.list();

The above query is retrieving all rows from the table.
Please let me know whats wrong in the above query and also let me know correct one.

- Naga


Top
 Profile  
 
 Post subject: like or not like ?
PostPosted: Wed Jan 03, 2007 9:23 am 
Beginner
Beginner

Joined: Wed Aug 31, 2005 3:54 am
Posts: 45
Try :
Query q = session.createQuery("from Test u where u.name not like 'Mu%' ");
List result = q.list();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 9:32 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Please use the code tags...

You can also try with the Criteria API:
Code:
Query q = session.createCriteria(this.getClass()).add(Restrictions.like("name", "Mu", MatchMode.START));
List result = q.list();

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 9:46 am 
Beginner
Beginner

Joined: Wed Aug 31, 2005 3:54 am
Posts: 45
Do it work ?

Don't forget to rate


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.