-->
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: how could i covert native sql with subquery to Criterion?
PostPosted: Mon Feb 23, 2009 2:27 am 
Newbie

Joined: Wed May 28, 2008 9:31 pm
Posts: 4
with the native sql "select * from tableA where tableA.Id in (select Id from tableA where tableA.name like "M%") ", how could i make it with help of Subqueries?


Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 7:05 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Well, why not simplifying your query to: "select * from tableA where name like 'M%'"?

Anyway, I guess your query is just an example, so here is the criteria:
Code:
DetachedCriteria d = DetachedCriteria.forClass(YourEntityA.class).add(Restrictions.eq("name", 1)).setProjection(Projections.id());
       
Criteria c = session.createCriteria(YourEntityA.class).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.