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