Joined: Wed Apr 15, 2009 5:44 am Posts: 2 Location: India
|
hi, i m new in hibernate, i m trying following code but it throws org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.yash.appraisal.hbeans.AppraisalHeadDt#com.yash.appraisal.hbeans.AppraisalHeadDt@18f06f[]]
the code i was trying is as follows: . . . AppraisalData insertData = new AppraisalData(); // this is parent table
//Head Details AppraisalHeadDt appraisalHeadDt = new AppraisalHeadDt(); AppraisalHeadDt appraisalHeadDt1 = new AppraisalHeadDt(); AppraisalHeadDt appraisalHeadDt2 = new AppraisalHeadDt(); appraisalHeadDt.setAppraisalData(insertData); appraisalHeadDt.setAccessMode("V"); appraisalHeadDt.setAppraiserComments("not Done!!!!"); appraisalHeadDt.setAppraiserId("E10"); appraisalHeadDt.setAppraiserRating(4); appraisalHeadDt.setHeadType("IBP"); appraisalHeadDt1.setAppraisalData(insertData); appraisalHeadDt1.setAccessMode("V"); appraisalHeadDt1.setAppraiserComments("Done!!!!"); appraisalHeadDt1.setAppraiserId("E10"); appraisalHeadDt1.setAppraiserRating(2); appraisalHeadDt1.setHeadType("FIN");
appraisalHeadDt2.setAppraisalData(insertData); appraisalHeadDt2.setAccessMode("V"); appraisalHeadDt2.setAppraiserComments("not Done Properly!!!!"); appraisalHeadDt2.setAppraiserId("E10"); appraisalHeadDt2.setAppraiserRating(1); appraisalHeadDt2.setHeadType("CS"); Set<AppraisalHeadDt> appraisalHeadDts = new HashSet<AppraisalHeadDt>(); appraisalHeadDts.add(appraisalHeadDt); appraisalHeadDts.add(appraisalHeadDt1); appraisalHeadDts.add(appraisalHeadDt2); insertData.setAccessMode("V"); insertData.setAppraisalFromDate(date); insertData.setAppraisalToDate(new Date(time_ms)); insertData.setName("XYZ"); insertData.setTimestamp(date);
insertData.setCompId(pk_insert); insertData.setAppraisalHeadDts(appraisalHeadDts); HibernateDAO dao = new HibernateDAO(); dao.startNewAppraisal(insertData); // here i m calling save() . . . and my HBM file for AppraisalData is as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="com.yash.appraisal.hbeans.AppraisalData" table="APPRAISAL_DATA" schema="TESTUSER" lazy="false" dynamic-insert="true" dynamic-update="true"> <composite-id name="compId" class="com.yash.appraisal.hbeans.AppraisalDataPK"> <key-property name="appraisalId" type="string" column="APPRAISAL_ID" length="50" /> <key-property name="empId" type="string" column="EMP_ID" length="10" /> </composite-id> <property name="accessMode" type="string" column="ACCESS_MODE" length="1" /> <property name="appraisalFromDate" type="date" column="APPRAISAL_FROM_DATE" length="7" /> <property name="appraisalToDate" type="date" column="APPRAISAL_TO_DATE" length="7" /> <property name="name" type="string" column="NAME" length="50" /> <property name="timestamp" type="date" column="TIMESTAMP" length="7" />
<!-- Associations --> <!-- bi-directional many-to-one association to AppraisalHeadDt --> <set name="appraisalHeadDts" inverse="true" cascade="all" fetch="select" lazy="false" > <key> <column name="APPRAISAL_ID" /><!-- a foreign key in APPRAISAL_HEAD_DT referencing the primary key of this table. --> <column name="EMP_ID" /><!-- a foreign key in APPRAISAL_HEAD_DT referencing the primary key of this table. --> </key> <one-to-many class="com.yash.appraisal.hbeans.AppraisalHeadDt" /> </set> </class> </hibernate-mapping>
HBM for AppraisalHeadDt table is as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="com.yash.appraisal.hbeans.AppraisalHeadDt" table="APPRAISAL_HEAD_DT" schema="TESTUSER" lazy="false" dynamic-insert="true" dynamic-update="true"> <composite-id> <key-many-to-one name="appraisalData" class="com.yash.appraisal.hbeans.AppraisalData"> <column name="APPRAISAL_ID"></column> <column name="EMP_ID"></column> </key-many-to-one> </composite-id> <property name="accessMode" type="string" column="ACCESS_MODE" length="1" /> <property name="appraiserComments" type="string" column="APPRAISER_COMMENTS" length="500" /> <property name="appraiserId" type="string" column="APPRAISER_ID" length="4000" /> <property name="appraiserRating" type="integer" column="APPRAISER_RATING" length="22" /> <property name="headType" type="string" column="HEAD_TYPE" length="3" /> <property name="timestamp" type="date" column="TIMESTAMP" length="7" /> <!-- Associations --> <!-- bi-directional many-to-one association to AppraisalData --> <many-to-one name="appraisalData" class="com.yash.appraisal.hbeans.AppraisalData" cascade="all" lazy="false" insert="false" update="false" > <column name="APPRAISAL_ID" length="50" /> <column name="EMP_ID" length="10" /> </many-to-one> </class> </hibernate-mapping>
can anybody tell me where i m going wrong? thanks in advance.
|
|