-->
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.  [ 3 posts ] 
Author Message
 Post subject: Parent-Child -> NonUniqueObjectException, used to work
PostPosted: Sat Mar 06, 2004 3:03 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
HB 2.1.2

Hi,

The following setup was working fine with, IIRC, HB 2.0. Now, I'm getting the

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: test.Child

Mappings:
Code:
<hibernate-mapping schema="test">
    <class name="test.Parent" table="Parent" >

        <id name="id" type="int" unsaved-value="0">
            <generator class="sequence">
        ...
        </id>
        ...

        <bag name="children" inverse="true" lazy="true" cascade="all">
            <key column="parentId"/>
            <one-to-many class="test.Child"/>
        </bag>

    </class>
</hibernate-mapping>


<hibernate-mapping schema="test">
    <class name="test.Child" table="Child" >

        <id name="id" type="int" unsaved-value="0">
            <generator class="sequence">
            </generator>
        </id>

        ...
        <many-to-one name="Parent" class="test.Parent" column="parentId"
            not-null="true" unique="false"/>

    </class>
</hibernate-mapping>

Code:
Code:
...
            for (int i = 0; i < blockSize; i++) {
                Parent parent = new Parent();
               
                Child Child = new Child();
                Child.setParent(parent);
               
                List children = new ArrayList();
                children.add(Child);
                parent.setChildren(children);
                parents.add(Parent);
            }

            Transaction tx = session.beginTransaction();
            for (int i = 0; i < blockSize; i++) {
                // with i = 1 the exception is thrown on save()
                session.save(securities.get(i));
            }
            session.flush();
            tx.commit();
...




It appears that HB goes to the db to get ids for the first 2 Parents but never tries to get the id for the Child.

Any ideas? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 6:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You are mistaken.
Show the real code + log

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 11:50 am 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
Yes, you're right.

There is also <timestamp name="tstamp"/> property and it appears that it now overrides the id's unsaved-value="0". It used to work with some previous version on HB though

Once I changed the timestamp to
Code:
<timestamp name="tstamp" unsaved-value="undefined"/>
the problem went away. Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.