-->
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.  [ 3 posts ] 
Author Message
 Post subject: Howto query objects they are not in many-to-many assoc
PostPosted: Sun Nov 20, 2005 6:23 am 
Newbie

Joined: Tue Nov 01, 2005 12:31 pm
Posts: 5
Hi,

I've a Customers and Provisioners and a many-to-many assoc between them. Now I try to search all Customers, wich doesn't associated with provisioners. And thats with Criteria.

All what I found for it, is to query 'which customers have a association'. But not for the Negation.

The Restrictions.not doesnt work for it, see above. What I need, looks as SQL with subselect as follows:

Code:
select * from customer where customer.id not in (select customer_id from myassoc where provisioner_id not in (select provisioner_id from provisioner where name = 'blah')


An example criteria which is near to the solution, i think, is:

Code:
criteria = Utils.getCurrentSession().createCriteria(Customer.class);
criteria.createAlias("myassoc", "my" );
criteria.add(Restrictions.not(Restrictions.ilike("my.shortName", "blah")));


But this find's nothing, since it searches only for customers with a association that's not in the current type. And all customers without a association are completely ingored.

What I need is a left outer join or a Expression for the 'not in' subselect.

Could anyone point me to a solution or some docs where I could find more on this.

Regards
Steffen...

Hibernate version: 3.1rc3


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 10:00 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
I'm not sure, but maybe Restrictions.isEmpty and a corresponding condition on the collection might work.

Something like this:
Code:
crit.add( Restrictions.isEmpty( "subitems" ) ).createCriteria( "subitems" ).add( Restrictions.ne( "name", "blah" ) )


I think, it's worth a try.

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 12:56 pm 
Newbie

Joined: Fri Sep 03, 2004 9:11 am
Posts: 6
I had a simmilar problem and the Restrictions.isEmpty solved my problem. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.