-->
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: HQL Question: (Simple) many-to-many Query
PostPosted: Wed Jan 16, 2008 6:21 am 
Newbie

Joined: Wed Jan 16, 2008 5:35 am
Posts: 1
Hello together,

i have this simple bidirectional many-to-many association with a join table:

Person.java

[..]
@ManyToMany(targetEntity = Area.class, cascade = {
CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@JoinTable(name = "addr_person_to_area", joinColumns = { @JoinColumn(name = "person_nr") }, inverseJoinColumns = { @JoinColumn(name = "fachgebiet_nr") })
private List<Area> area;
[..]



Area.java

[...]
@ManyToMany(mappedBy = "area", targetEntity = Person.class)
private List<Person> person;
[...]



It works just fine.
But which HQL-Statement would I use if I wanted the following:

"return all AREA Objects that are NOT associated with a specific PERSON Object"


It seems I'm not getting this done right (tried it with joins/fetch etc).

Any help/ links appreciated.

Thank you very much in advance
Timo


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 1:59 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Provided you defined proper "equals" and "hashCode" methods in your Person and Area classes, you could get all the Areas that are related, then a list of all the Areas, and then subtract with removeAll (Java way, not Hibernate).

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: Re: HQL Question: (Simple) many-to-many Query
PostPosted: Wed Jan 16, 2008 2:06 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
This might do it for you:

Code:
select ar from Area ar where ar.person is empty




Farzad-


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.