-->
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 in oracle
PostPosted: Tue Apr 26, 2005 2:28 am 
Newbie

Joined: Tue Apr 26, 2005 2:22 am
Posts: 5
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.8

Mapping documents:
<hibernate-mapping>
<class name="test.ChildPO" table="CHILD" >
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">TEST_SEQ</param>
</generator>
</id>
<many-to-one name="parent" class="test.ParentPO" column="PARENTID" />
</class>
<class name="test.ParentPO" table="PARENT">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">F_LOG_SEQ</param>
</generator>
</id>
<bag name="children" cascade="all" >
<key column="PARENTID"/>
<one-to-many class="test.ChildPO"/>
</bag>
</class>
</hibernate-mapping>


java code:
ParentPO parent = new ParentPO();
ChildPO child = new ChildPO(parent);
ChildPO child2 = new ChildPO(parent);
List list = new ArrayList();
list.add(child);
list.add(child2);
parent.setChildren(list);
session.save(parent);
session.flush();
System.out.println("dddddddddddddddddddddddddddddddddddddddddddddddddddddd") ;
ChildPO child3 = new ChildPO();
child3.setParent(parent);
session.save(child3);
session.flush();


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

at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1687)

at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1453)

at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1480)

at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1403)

at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)

at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)

at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)

at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)

at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)

at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:962)

at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:868)

at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:790)

at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:749)

at b2bmanage.pub.db.TestSession.main(TestSession.java:27)


oracle 9.0

class:
public class ParentPO {
private java.util.List children;
private long id;
public ParentPO() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public java.util.List getChildren() {
return children;
}
public void setChildren(java.util.List children) {
this.children = children;
}

}
public class ChildPO {
private ParentPO parent;
private long id;
public ChildPO() {
}
public ChildPO(ParentPO parent) {
this.parent = parent;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public ParentPO getParent() {
return parent;
}
public void setParent(ParentPO parent) {
this.parent = parent;
}

}


Debug level Hibernate log excerpt:

i don't know why, can anyone help me out ,thanks in advance.


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.