Hibernate version: 2.1.6
Forgive me, but I can't find the manual reference regarding a problem I'm having.
I have a Many-to-Many association between a User object and one or more Group objects to which they may belong. The mapping is set up correctly, groups many be assigned and saved, and when the User is loaded, their Set of Groups is correctly populated.
However, the contains() method is failing to find Groups within the Set. The method User.isInGroup(String pGroupName) does the following:
Code:
Group group = new Group() ;
group.setName(pGroupName) ;
return this.mGroups.contains(pGroupName) ;
I have also redefined the Group.equals() method to consider two Groups equal if the name is equal. As defined in the Set interface, the contains() method:
Quote:
Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)).
From debug statements, I can see all the previous is true.
Furthermore, I've looked at the net.sf.hibernate.collection.Set object used by Hibernate, and it doesn't do anything funky with the contains() method.
Finally, to quote the Hibernate Advanced FAQ,
http://www.hibernate.org/117.htmlQuote:
What column should I map the <index> tag of an array or List to?
You need a seperate table column holding the array or List index (the i in foo[i])! If your relational model doesn't have an index column, use a Set instead. This seems to put people off who assume that List should just be a more convenient way of accessing an unordered collection. Hibernate collections strictly obey the actual semantics attached to the Set, List and Map interfaces.
So why doesn't my contains() method find the Group?
Thanks for any help or insight.
Lukas