-->
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 when cascade save of union-subclass
PostPosted: Wed Jun 11, 2008 4:12 am 
Newbie

Joined: Wed Jun 11, 2008 3:30 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.6

Mapping documents:

<hibernate-mapping>
<class entity-name="Persoana" table="PERSOANA">
<id name="id" type="long" column="ID">
<generator class="increment" />
</id>
<property name="pozitie" type="integer" column="POZITIE" />
<property name="representant" type="string" not-null="true" length="48" column="REPRESENTANT" />
<property name="adresa" type="string" length="64" column="ADRESA" />
<property name="identitate" type="string" length="16" column="IDENTITATE" />
<property name="eliberat" type="string" length="24" column="ELIBERAT" />
<property name="informatie" type="string" length="64" column="INFORMATIE" />
</class>
</hibernate-mapping>


<hibernate-mapping>
<typedef class="lang.Cont" name="Cont" />
<class entity-name="Cont" abstract="true" table="CONT">
<id name="id" type="long" column="ID">
<generator class="foreign">
<param name="property">Persoana</param>
</generator>
</id>
<property name="cont" type="Cont">
<column name="CREDIT_CREANTE" />
<column name="CREDIT_RESTANTE" />
<column name="CREDIT_PENALITATI" />
<column name="DEBIT_CREANTE" />
<column name="DEBIT_RESTANTE" />
<column name="DEBIT_PENALITATI" />
</property>
<one-to-one name="Persoana" entity-name="Persoana" constrained="true" />
<union-subclass entity-name="Cont00" table="CONT_00" />
<union-subclass entity-name="Cont01" table="CONT_01" />
<union-subclass entity-name="Cont02" table="CONT_02" />
<union-subclass entity-name="Cont03" table="CONT_03" />
<union-subclass entity-name="Cont04" table="CONT_04" />
<union-subclass entity-name="Cont05" table="CONT_05" />
<union-subclass entity-name="Cont06" table="CONT_06" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

sess.beginTransaction();
sess.save("Persoana",map);
for(Leaf l:leaves) {
//Se adauga conturile
// l.getId() goes from 00 to 06
Map tmp=new HashMap();
tmp.put("Persoana",map);
tmp.put("cont", new Cont());
sess.save("Cont"+l.getId(),tmp);
}
sess.getTransaction().commit();

Full stack trace of any exception that occurs:

Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [Cont01#1158]
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:168)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at fiscal.adapt.AdaptC.addPersoana(AdaptC.java:36)
at fiscal.persoana.ModelC.addPersoana(ModelC.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 35 more

Name and version of the database you are using:

Postgres 8.2

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

To the second itaration 00,01 the exception is generated.
I think there is no reason to generate it, as the two entities Cont00 and Cont01 represent two differrent classes.


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.