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]