-->
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: problem updating element in a collection..
PostPosted: Mon Sep 19, 2005 6:57 pm 
Newbie

Joined: Fri Sep 09, 2005 11:11 am
Posts: 19
<class name="Order" table="ORDERS">
<id name="id" column="ID"/>
<set name="items">
<key column="id"/>
<one-to-many class="Item"/>
</set>
</class>
<class name="Item" table="ITEMS">
<id name="id" column="ID"/>
<property name="info"/>
</class>

======================
Order order = (Order) session.get(Order.class, new Long(1));
Iterator it = order.getItems().iterator();
while (it.hasNext())
{
Item item = (Item) it.next();
item.setInfo("hello world");
}
tx.commit();
======================
Exception occur [constriant violation of Item table primary key]. Instead of updating an existing record, the log file indicates that hibernate tried to insert a record with an already exist primary key. Why??


Top
 Profile  
 
 Post subject: Re: problem updating element in a collection..
PostPosted: Tue Sep 20, 2005 1:30 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
zollen wrote:
<class name="Order" table="ORDERS">
<id name="id" column="ID"/>
<set name="items">
<key column="id"/>
<one-to-many class="Item"/>
</set>
</class>
<class name="Item" table="ITEMS">
<id name="id" column="ID"/>
<property name="info"/>
</class>

Your mapping does not make a lot of sense to me. I would expect something like
Code:
<class name="Order" table="ORDERS">
<id name="id" column="ID"/>
<set name="items">
   <key column="ORDERS_FK"/>
   <one-to-many class="Item"/>
</set>
</class>
...

This defines that table ITEM contains a foreign key to ORDERS.

Was this a cut & paste error or do you mean it? If the latter, could you please provide your database create statements or more information on what you intend to do.

Erik


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.