-->
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.  [ 1 post ] 
Author Message
 Post subject: ManyToMany object relations doensn't work correctly
PostPosted: Fri Dec 10, 2010 12:21 pm 
Newbie

Joined: Mon Apr 30, 2007 10:58 am
Posts: 5
Hi,

I've a big problem with a ManyToMany relation. I'm using two objects User and AccessRight.

The User object has an attribute
Code:
@OneToMany(mappedBy = "user", cascade = { CascadeType.ALL })
@Sort(type = SortType.NATURAL)
private SortedSet<AccessRight> accessRights;

Later on I have following logic used in my code:
Code:
for (AccessRight accessRight : user.getAccessRights()) {
   for (User deputy : accessRight.getDeputies()) {
      System.out.println(deputy.getAccessRights().size());
   }
}

The AccessRight object has the attribute
Code:
@ManyToMany
@JoinTable(name = "accessright_deputy", joinColumns = { @JoinColumn(name = "accessright_id") }, inverseJoinColumns = { @JoinColumn(name = "user_id") })
@Sort(type = SortType.NATURAL)
private SortedSet<User> deputies;

The strange thing now is, that I always get a size of "1" by this logic, even the user has more than one access right.

Can anybody tell me, what's wrong with the code? Debugging the last 8 hours on this thing and doesn't find the mistake... :-(. Or is this a bug in Hibernate and how can I work around this?

A big thank you to the person who can help here!

Cheers,
Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.