When I try to update an Object which Has many to one relation and cascade=all,
I get the Error
ORA-02291: integrity constraint (AMS.SYS_C0059678) violated - parent key not found
My
Code:
<hibernate-mapping>
<class name="hmil.service.basic.model.ServiceDet" table="RDMNDET_TB">
<composite-id>
<key-property name="MNDET_CMPN_NO" type="java.lang.String"></key-property>
<key-property name="MNDET_CORP_NO" type="java.lang.String"></key-property>
<key-property name="MNDET_DLR_NO" type="java.lang.String"></key-property>
<key-property name="MNDET_SCTN_ID" type="long"></key-property>
<key-property name="MNDET_YEAR_MONTH" type="java.lang.String"></key-property>
</composite-id>
<property name="MNDET_WORKING_DAYS" type="long" />
<property name="MNDET_MECH_BAY" type="long" />
<property name="MNDET_BODY_BAY" type="long" />
more columns.....
<many-to-one name="MNDET_DLR" class="hmil.com.dlr.model.DealerOrg" fetch="join" cascade="none" insert="false" update="false">
<column name="MNDET_CMPN_NO" />
<column name="MNDET_CORP_NO" />
<column name="MNDET_DLR_NO" />
<column name="MNDET_SCTN_ID" />
</many-to-one>
<many-to-one name="MNDET_ATD" class="hmil.service.basic.model.AdvTechDet" cascade="all" column="MNDET_ATDET_ID" fetch="join"></many-to-one>
<many-to-one name="MNDET_ROD" class="hmil.service.basic.model.RepairOrderDet" cascade="all" column="MNDET_RODET_ID" fetch="join"></many-to-one>
<many-to-one name="MNDET_EPD" class="hmil.service.basic.model.DepDet" cascade="all" column="MNDET_EPDET_ID" fetch="join"></many-to-one>
<many-to-one name="MNDET_CSI" class="hmil.service.basic.model.CSIDet" cascade="all" column="MNDET_CSI_ID" fetch="join"></many-to-one>
<many-to-one name="MNDET_EMP" class="hmil.com.general.model.Employee" cascade="none" column="MNDET_EMP_ID" fetch="join" insert="false" update="false" ></many-to-one>
</class>
</hibernate-mapping>
And My JAVA code is
Code:
HibernateUtils.currentSession().beginTransaction();
srvDetObj = new ServiceDet();
//call Setter methods
//Repair Order
RepairOrderDet roDet = new RepairOrderDet();
roDet.setRODET_CMPN_NO(Common.CMPN_NO);
// more setter methods
//Advisor Technician
AdvTechDet atDet = new AdvTechDet();
atDet.setATDET_CMPN_NO(Common.CMPN_NO);
// more setter methods
//Dealer Enhancement Program
DepDet depDet = new DepDet();
depDet.setEPDET_CMPN_NO(Common.CMPN_NO);
// more setter methods
//CSI
CSIDet csiDet = new CSIDet();
csiDet.setCSIDT_CMPN_NO(Common.CMPN_NO);
// more setter methods
srvDetObj.setMNDET_ROD(roDet);
srvDetObj.setMNDET_ATD(atDet);
srvDetObj.setMNDET_EPD(depDet);
srvDetObj.setMNDET_CSI(csiDet);
HibernateUtils.currentSession().save(srvDetObj);
HibernateUtils.currentSession().getTransaction().commit();
This Save was working earlier, but not sure what changes I did, now it does not work.
The strange thing is even if i change the save to update or save or update, it always tries to insert the records. and then DB error is thrown as unique key is violated
Any help is appreciated.