-->
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.  [ 2 posts ] 
Author Message
 Post subject: Bug or by design?
PostPosted: Thu Dec 11, 2003 2:51 am 
Newbie

Joined: Fri Dec 05, 2003 12:44 am
Posts: 16
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 3:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yep, looks like a bug in your code. Probably you don't implement equals()/hashCode() properly for the composite-element class.


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

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.