First, let me say that Hibernate is awesome. I'm just now playing around with it, but really like! I'm seeing one weird behavior though:
Discription: The 'contains' method is returning false, but I know the given object is (the only object) in the set because:
a)It's iterator finds it:
assertEquals(hibernateSet.iterator().next(), givenObject);
//passes
b)Wrapping the hibernate Set in a java.util.HashSet results in 'contains' returning true:
jdkSet = new HashSet(hibernateSet);
assertTrue(jdkSet.contains(givenObject);
Hibernate Version: 2.1.4
Database Version: MySQL, 4.0.20a
mapping documents:
<hibernate-mapping>
<class name="tomcattest.PetOwner" table="pet_owner">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name" column="name" type="string"
length="15" not-null="false"/>
<set name="pets" cascade="all" inverse="true" lazy="true">
<key column="pet_owner_id"/>
<one-to-many class="tomcattest.Pet"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="tomcattest.Pet" table="pet">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="false"/>
<generator class="uuid.hex"/>
</id>
<property name="name">
<column name="NAME" length="16" not-null="true"/>
</property>
<property name="sex"/>
<property name="weight"/>
<many-to-one name="owner" class="tomcattest.PetOwner"
column="pet_owner_id"/>
<joined-subclass name="tomcattest.Cat" table="cat">
<key column="id"/>
<property name="outdoorCat" column="is_outdoor"/>
</joined-subclass>
<joined-subclass name="tomcattest.Dog" table="dog">
<key column="id"/>
<property name="huntingDog" column="is_huntingdog"/>
</joined-subclass>
</class>
</hibernate-mapping>
Java Code:
Failing Test:
...
Session session = HibernateUtil.currentSession(testConn);
Transaction tx= session.beginTransaction();
//write some data
PetOwner jenn = new PetOwner();
jenn.setName("Jenn");
Cat mama = new Cat();
mama.setName("Mama Kitty");
mama.setSex('F');
mama.setWeight(8);
mama.setOwner(jenn);
mama.setOutdoorCat(true)
session.saveOrUpdate(jenn);
//retrieve the data
List petOwners = session.find("From PetOwner");
assertEquals(1,petOwners.size());
assertTrue(petOwners.contains(jenn));
Set allPets = ((PetOwner)petOwners.get(0)).getPets();
System.out.println("Broken Set: " + allPets.getClass().getName());
//Above line outputs: net.sf.hibernate.collection.Set
assertEquals(allPets.size(),1);
assertEquals(allPets.iterator().next(), mama);
//Above assertion passes
assertTrue(allPets.contains(mama));
//Above assertion fails, BUG?
tx.rollback();
HibernateUtil.closeSession();
...
Thanks,
Mike
|