-->
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: Hibernate criteria subquery
PostPosted: Tue Feb 03, 2009 6:36 pm 
Newbie

Joined: Fri Dec 12, 2008 8:59 pm
Posts: 10
Hi,

I need to construct a subquery using hibernate critera,

am able to create criteria and add resrictions, but using subquery in criteria its confused.

i need query like this

select * from trans a where a.id in (select max(id) from trans b where a.userid=b.userid)

anyone plz suggest reg. this


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 4:08 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You can create a subselect using DetachedCriteria:

Code:
  DetachedCriteria d = DetachedCriteria.forClass(Trans.class, "t2").add(Restrictions.eq("userid", "t1.userid")).setProjection(Projections.max("id"));
  session.createCriteria(Trans.class, "t1").add(Property.forName("id").in(d));


Rating is welcome. ;-)

_________________
-----------------
Need advanced help? http://www.viada.eu


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.