-->
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: Could you please help me how to create Criteria for followin
PostPosted: Sun Nov 24, 2013 9:53 pm 
Newbie

Joined: Sun Nov 24, 2013 9:51 pm
Posts: 1
select p from post p left join p.node n where p.nodeId in
(select nodeId from node where bookId = :bookId and nodeType = Test_NODE' )
and p.nodeId=n.nodeId and p.status is not 'DELETED'


Top
 Profile  
 
 Post subject: Re: Could you please help me how to create Criteria for followin
PostPosted: Mon Nov 25, 2013 5:58 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
These links should help:
Stack Overflow: http://stackoverflow.com/questions/3738555/hibernate-criteria-subquery
Hibernate Documentation: http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch17.html#querycriteria-detachedqueries

It actually depends how you have mapped the entities but it should look something like this (I haven't tried it):

Code:
DetachedCriteria subquery = DetachedCriteria.forClass( Node.class )
    .add( Restrictions.eq( "bookId", ":bookId" )    )
    .add( Restrictions.eq( "nodeType", "Test_NODE" ) )
    .setProjection( Property.forName( "nodeId" ) );

DetachedCriteria.forClass( Post.class, "p" )
    .createCriteria( "p.node", "n", JoinType.LEFT_OUTER_JOIN )
    .add( Restrictions.ne( "p.status", "DELETED" ) )
    .add( Restrictions.ne( "p.nodeId", "n.nodeId" ) )
    .add( Subqueries.in( "p.nodeId", subquery ) );



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.