-->
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: Really stuck! Another object was associated with this id
PostPosted: Sat Oct 25, 2003 9:33 pm 
Newbie

Joined: Sat Oct 25, 2003 9:05 pm
Posts: 2
Location: Sydney
Hello there,

I am really stuck!
I have to classes an Order that contains a Collection (Set) of OrderItems. The ids are taken care off via sequence (PSQL).

If I add one OrderItem to the Order and save the Order all is fine. However, if I add two or more OrderItems to the Order I get a:

Code:
net.sf.hibernate.HibernateException: Another object was associated with this id (the object with the given id was already loaded): [OrderItem#0]


Code:
Order    order = new Order(  );
order.add( new OrderItem() );
sess.save( order );

is ok.

Code:
Order    order = new Order(  );
order.add( new OrderItem() );
order.add( new OrderItem() );
sess.save( order );

is not ok????

Surely Hibernate must be able to distingish the two newly created objects.
I am fully aware of the limitation that one can not have two loaded objects pointing to the same DB row, but in this case none of the objects do exist? (http://hibernate.bluemars.net/117.html#A19)

Please help! I do not understand this. Is there an easy explanation or solution. What am I missing?

Thanks Bernie

Code:
public class Order
{
    private long      _id;
    private Set        _items = new HashSet(  );
    public void add( OrderItem item)
    {
        _items.add( item );
    }
...
}

public class OrderItem
{
    private long      _id;
...
}

<hibernate-mapping>
    <class
        name="OrderItem"
        table="T_ORDER_ITEM"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="long"
        >
            <generator class="sequence">
            </generator>
        </id>
...


<hibernate-mapping>
    <class
        name="Order"
        table="T_ORDER"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="long"
        >
            <generator class="sequence">
            </generator>
        </id>

        <set
            name="items"
            lazy="true"
            inverse="false"
            cascade="all"
            sort="unsorted"
        >

              <key
                  column="order_fk"
              />

              <one-to-many
                  class="OrderItem"
              />
        </set>
...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 25, 2003 9:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
set unsaved-value="0"


Top
 Profile  
 
 Post subject: I works thanks.
PostPosted: Sat Oct 25, 2003 10:31 pm 
Newbie

Joined: Sat Oct 25, 2003 9:05 pm
Posts: 2
Location: Sydney
Thanks I believe that has fixed the issue


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.