NItin Sehra

Greenhorn
+ Follow
since May 31, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by NItin Sehra

I will reiterate my problem :
Parent Class mapping :
<set name="test" inverse="true" cascade="all" >
<key column="CONTROLAGENTID" />
<one-to-many class="com.freightdesk.intelliagent.model.DBActionModel" />
</set>

Child Class mapping :
<many-to-one name="controlAgent"
class="com.freightdesk.intelliagent.model.ControlAgentModel"
column="CONTROLAGENTID" insert="true" update="true" />

Java Code :
DBActionModel dbModel = new DBActionModel();
dbModel.setControlAgent(controlAgentModel);
controlAgentModel.getTest().add(dbModel);
session.save(controlAgentModel);

The Hibernate excute first insert on parent and then try to update child




Any help
I got this error

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0

Any idea would be of great help
No i am not assining alertid ,the alertid is coming from a database sequnce,
i just modifed my child xml as

<id name="intelliAgentAlertId" type="long">
<column name="ALERTID" sql-type="number" not-null="true"/>
<generator class="sequence"> <param name="sequence">IA_ALERTID</param>
</generator>
</id>

ANd get the Hibernate debug as :
Hibernate: select IA_CONTROLAGENTID.nextval from dual

Hibernate: insert into IA_CONTROLAGENT (CONTROLAGENTNAME, CONTROLAGENTDESC, DEFAULTALERTSUBJECT, DEFAULTALERTTEMPLATE, status, lastUpdateUserId, lastUpdateTimestamp, createUserId, domainName, LASTEXECUTEDTIME, CONTROLAGENTID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Hibernate: update IA_ALERT set CONTROLAGENTID=?, ALERTTYPECODE=?, ALERTTARGET=?, ALERTSUBJECT=?, ALERTTEMPLATE=?, PRIORITY=?, ALLOWRICHTEXT=?, USEDEFAULTS=?, status=?, lastUpdateUserId=?, lastUpdateTimestamp=?, createUserId=?, createTimestamp=?, domainName=? where ALERTID=?

I don't understand y hibernate is not inserting IA_ALERT record first.
i have done show-sql true ,is there is other verbose option avilable for debugging hibernate.
Thanks for reply
I am trying to do a simple parent child save assuming hibernate will insert child record when i will call save on parent.

Parent xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="none" default-access="property" auto-import="true">
<class name="com.freightdesk.intelliagent.model.ControlAgentModel" table="IA_CONTROLAGENT">
<id name="controlAgentId" type="long">
<column name="CONTROLAGENTID" sql-type="number" not-null="true"/>
<generator class="sequence">
<param name="sequence">IA_CONTROLAGENTID</param>
</generator>
</id>
<property name="controlAgentName">
<column name="CONTROLAGENTNAME" />
</property>
<property name="controlAgentDesc">
<column name="CONTROLAGENTDESC" />
</property>
<property name="defaultAlertSubject">
<column name="DEFAULTALERTSUBJECT" />
</property>
<property name="defaultAlertTemplate">
<column name="DEFAULTALERTTEMPLATE" />
</property>
<property name="status"/>
<property name="lastUpdateUserId"/>
<property name="lastUpdateTimestamp"/>
<property name="createUserId"/>
<property name="createTimestamp" insert="false" />
<property name="domainName"/>
<property name="lastExecutedTimestamp">
<column name="LASTEXECUTEDTIME" />
</property>
<bag name="alertList" cascade="all-delete-orphan" inverse="true" >
<key> <column name="CONTROLAGENTID" not-null="true" /></key>
<one-to-many class="com.freightdesk.intelliagent.model.AlertActionModel"/>
</bag>
</class>
</hibernate-mapping>


Child xml :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="none" default-access="property" auto-import="true">
<class name="com.freightdesk.intelliagent.model.AlertActionModel" table="IA_ALERT">
<id name="intelliAgentAlertId" type="long">
<column name="ALERTID" sql-type="number" not-null="true"/>
<generator class="assigned">
<param name="sequence">IA_ALERTID</param>
</generator>
</id>
<property name="agentID" not-null="true">
<column name="CONTROLAGENTID" />
</property>
<property name="intelliAgentAlertTypeCode">
<column name="ALERTTYPECODE" />
</property>
<property name="intelliAgentAlertTarget">
<column name="ALERTTARGET" />
</property>
<property name="intelliAgentAlertSubject">
<column name="ALERTSUBJECT" />
</property>
<property name="intelliAgentAlertTemplate">
<column name="ALERTTEMPLATE" />
</property>
<property name="intelliAgentAlertPriority">
<column name="PRIORITY" />
</property>
<property name="allowRichText">
<column name="ALLOWRICHTEXT" />
</property>
<property name="useDefaults">
<column name="USEDEFAULTS" />
</property>
<property name="status"/>
<property name="lastUpdateUserId"/>
<property name="lastUpdateTimestamp"/>
<property name="createUserId"/>
<property name="createTimestamp" insert="false" />
<property name="domainName"/>
<many-to-one name="controlAgent" not-null="true" column="CONTROLAGENTID" insert="false" update="false" />

</class>
</hibernate-mapping>

Now when i do a simple save the parent get created but child record are not inserted.
The Hibernate debug show:
Insert on parent
Update on child

Please help me out , its been hours i m digging this problem