-->
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: Query with criteria Hibernate
PostPosted: Fri May 07, 2010 9:52 am 
Newbie

Joined: Fri May 07, 2010 9:47 am
Posts: 2
Hello, you excuse to me for my inglish... I have one information.
I must transformer one query SQL in criteria with Hibernate, but i do not know. The query with SQL is:
Code:
SELECT MAX(nickname) FROM test where nickname LIKE '%name%'


Thanks for you help ^^


Top
 Profile  
 
 Post subject: Re: Query with criteria Hibernate
PostPosted: Sat May 08, 2010 12:43 am 
Newbie

Joined: Tue Oct 24, 2006 7:47 pm
Posts: 4
Not in front of an IDE right now but try:

Code:
// create your criteria
Criteria criteria = session.createCriteria(Test.class);

// this is the "where" clause
criteria.add(Restrictions.like("nickname", "%name%"));

// a projection represents what you want to select (what you want "projected"). You want the max nickname
criteria.setProjection(Projections.max("nickname"));


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.