-->
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 by Example with sub Queries ?
PostPosted: Sat Feb 21, 2009 9:44 am 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
Hi Gurus,

I have two related tables as in the end of this message, and I have a Query by Example:

User u = new User();

// set search conditions in u here

Example example = Example.create(u).enableLike(MatchMode.EXACT);
Criteria cr = getSession().createCriteria(User.class).add(example);

above code works, what I'd like to add now is, the list of Users returned should not be in the Leader table, how to do this? Thanks,

Angelo

public class User {
private Long id;
String Code;
}

public class Leader {
Long id;
private User user;
...
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 8:14 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Add the following:
Code:
DetachedCriteria d = DetachedCriteria.forClass(Leader.class).setProjection(Projections.property("user"));

cr.add(Property.forName("id").notIn(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.