given the following mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="org.hibernate.test.Org" table="Org">
<id name="id" type="integer" unsaved-value="0">
<generator class="native"/>
</id>
<set name="cats" table="OrgCategory" cascade="all">
<key column="OrgID"/>
<composite-element class="org.hibernate.test.OrgCategory">
<property name="weight" />
<property name="cat" />
</composite-element>
</set>
</class>
</hibernate-mapping>
and the folowing code
Code:
package org.hibernate.test;
public class Org {
private int id;
private java.util.Set cats;
public Org() { }
public int getId() { return this.id; }
public void setId(int id) { this.id = id; }
public java.util.Set getCats() { return this.cats; }
public void setCats(java.util.Set cats) { this.cats = cats; }
}
Code:
package org.hibernate.test;
public class OrgCategory {
private int weight;
private int cat;
public OrgCategory() {}
public OrgCategory(int a, int b) { weight = a; cat = b; }
public int getWeight() { return this.weight; }
public void setWeight(int weight) { this.weight = weight; }
public int getCat() { return this.cat; }
public void setCat(int cat) { this.cat = cat;}
}
Code:
package org.hibernate.test;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import net.sf.hibernate.Session;
import net.sf.hibernate.util.SerializationHelper;
public class OllieTest extends TestCase
{
public OllieTest(String arg)
{
super(arg);
}
public void testCollectionNotRealyDirty()
throws Exception
{
Session s = openSession();
Org o = new Org();
java.util.Set cats = new java.util.HashSet();
cats.add(new OrgCategory(1,2));
cats.add(new OrgCategory(2,3));
o.setCats(cats);
s.save(o);
s.flush();
s.connection().commit();
s.close();
s = openSession();
o = (Org) s.get(Org.class, new Integer(o.getId()));
s.flush();
s.connection().commit();
s.close();
}
public static Test suite()
{
return new TestSuite(OllieTest.class);
}
public static void main(String[] args) throws Exception
{
TestRunner.run( suite() );
}
protected String[] getMappings()
{
return new String[]
{
"Org.hbm.xml"
};
}
}
When I run the test case why is the collection org.cats marked as dirty and recreated at the second flush? Is this a bug?
Thanks
Oliver Hutchison