-->
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.  [ 1 post ] 
Author Message
 Post subject: NonUniqueObjectException while persisting my object
PostPosted: Wed Mar 09, 2005 9:14 am 
Newbie

Joined: Mon Mar 08, 2004 4:10 am
Posts: 6
Hibernate-version: 2.1.6
Database : DB2 8.2
----------------------------
Hi. I have a problem as I use a Foo class that includes a Bar and Bar has Bar instance as next Bar. When I loaded the Foo instance and update the Bar instance of Foo with the nextBar, I take a NonUniqueObjectException.Because these two instances have the same id. So what should I do?

---------------------
class Foo{
Bar bar;
}

class Bar{
Bar nextBar;
}
----------------------
My application code is:

Foo foo = new Foo(); // have the same id with Bar
Bar bar = new Bar(); // have the same id with Foo
Bar bar2 = new Bar();
bar.setnextBar(bar2);
foo.setBar(bar);
session.update(foo,new Long(foo.getId()));
session.update(bar,new Long(foo.getBar().getId()));

-------------------------------
Mapping is:

<class name="fooDO" discriminator-value="foo" table="FOO">
<id column="ID" name="id" type="long">
<generator class="identity"></generator>
</id>
<subclass name="fooSubDO" discriminator-value="fooSub">
<one-to-one name="BarState" class="BarDO" constrained="false" cascade="save-update"
</subclass>
</class>

<class name="BarDO" discriminator value="BarState" table="BAR">
<id column="ID" name="id" type="long">
<generator class="identity"></generator>
</id>
<many-to-one name="owningFoo" class="fooSubDO" column="FooSubId" cascade="save-update"/>
<subclass name="BarFirstSubStateDO" discriminator-value="BarFirstSubState">
<property name="BarDate" type="java.sql.Date" column="BAR_DATE"/>
</subclass>
<subclass name="BarSecondSubStateDO" discriminator-value="BarFirstSubState">
</subclass>
</class>


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

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.