-->
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: identifier of an instance of ... altered from ... to ....
PostPosted: Fri Jun 17, 2005 10:33 am 
Newbie

Joined: Fri Jun 17, 2005 10:16 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

Mapping documents:


---------------------------------- Parent mapping file ----------------
<set inverse="true" name="tamBreakDown">
<key column="TBRK_ID" />
<one-to-many class="com.bticino.webcat.business.tam.TAMBreakDown" />
</set>
---------------------------------- Child mapping file ----------------
<hibernate-mapping >
<class name="com.bticino.webcat.business.tam.TAMBreakDown" table="TYPE_OF_BREAKDOWN">

<composite-id>
<key-many-to-one
class="com.bticino.webcat.business.tam.TAMDBean"
column="TBRK_ID"
name="Id"
/>
<key-property
column="TBRK_BREAKDOWN_TYPE"
name="breakdownDescription"
type="string"
/>
</composite-id>
</class>
</hibernate-mapping>

Problematic code:
while(it.hasNext())
{
TAMBreakDown breakdown = (TAMBreakDown)it.next();
TAMDBean tam=new TAMDBean();
tam.setTAMId(this.tamdbean.getTAMId());
breakdown.setId(tam);
session.save(breakdown);
}

session.flush();

A set of child objects [TAMBreakDown] are inserted into the DB. Exception is thrown at session.flush() statement.


Full stack trace of any exception that occurs:
net.sf.hibernate.HibernateException: identifier of an instance of com.bticino.webcat.business.tam.TAMBreakDown altered f
rom com.bticino.webcat.business.tam.TAMBreakDown@d5227524 to com.bticino.webcat.business.tam.TAMBreakDown@d5227524
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2642)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2465)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at com.bticino.webcat.service.TAMProcessor.addSCSInterface(TAMProcessor.java:2667)
at com.bticino.webcat.struts.action.ScsDetailsAction.addSCSInterface(ScsDetailsAction.java:740)
at com.bticino.webcat.struts.action.ScsDetailsAction.insert(ScsDetailsAction.java:126)



Name and version of the database you are using:
Oracle 10g (version 1)
----------------------------------------------
On creating a new Parent [TAMDBean], we need to insert 1 or more child objects [TAMBreakDown] into child table. So its one-to-many relationship for parent->child.

We are inserting child records in a WHILE loop, and at the end of loop when session.flush() is called the above given exception is thrown.

We are not able to understand the exact source of this exception.

Please let me know if more info is required.

Thanks in advance [nsevalia@yahoo.com]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 12:05 pm 
Regular
Regular

Joined: Thu Apr 21, 2005 9:05 am
Posts: 50
Location: Boston, U.S
You need not loop over the child elements and save it.
You are not making the advantages of Hibernate.

In Parent Class
Keep a collection element that will contain child elements.
specify the collection name in the one-to-many mapping.

Your save code would be as simple as
session.save(parentObject);

Both Parent and child table will be populated.
Refer to hibernate documentation it has a detailed examples.


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.