hi, I have two hibernate mapping files for tables TRPJOB_RPT_PARM(parent) and TRPJOB_RPT_PARM_VAL(child). They should have one to many relationship.
In TRPJOB_RPT_PARM table JOB_RPT_PARM_ID is the key. In TRPJOB_RPT_PARM_VAL, I dont ve a primary key column so I am declaring a composite key in the mapping file containg
JOB_RPT_PARM_ID and VALUE columns.
I face the problem when I try to save to TRPJOB_RPT_PARM. It should automatically save the values to TRPJOB_RPT_PARM_VAL. It saves it. but
JOB_RPT_PARM_ID gets filled with 0 values, where as it is supposed to get the values from JOB_RPT_PARM_ID in TRPJOB_RPT_PARM table.
If I make inverse=false, in one-to-many relationship in mapping.xml then it works fine. But then deletion gives me the problem as Hibernate is trying to update the foreign key column(JOB_RPT_PARM_ID) to null instead of deleting. I get Constraing violated exception can not delete the collection.
pls find below the hibernate mapping files.
parent file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.metlife.ins.ereport._2.bi.model.Parameter"
table="TRPJOB_RPT_PARM"
schema="F0654DBA"
>
<meta attribute="class-description" inherit="false">
com.metlife.ins.ereport._2.appl.model.hibernate
</meta>
<meta attribute="implement-equals" inherit="false">true</meta>
<id
name="jobRptParmId"
type="long"
column="JOB_RPT_PARM_ID"
>
<generator class="sequence">
<param name="sequence">TRPPKG_PARM_SEQ</param>
</generator>
</id>
<property
name="jobRptId"
type="long"
column="JOB_RPT_ID"
not-null="true"
insert="false"
update="false"
/>
<many-to-one name="parentReport" column="JOB_RPT_ID"
class="com.metlife.ins.ereport._2.bi.model.Report"></many-to-one>
<property
name="parmId"
type="long"
column="PARM_ID"
/>
<property
name="name"
type="java.lang.String"
column="PARM_NM"
/>
<!-- Associations -->
<bag name="selectedValues" table="TRPJOB_RPT_PARM_VAL" inverse="false" cascade="all,delete-orphan">
<key>
<column name="JOB_RPT_PARM_ID"/>
</key>
<one-to-many class="com.metlife.ins.ereport._2.bi.model.ParameterValue" />
</bag>
</class>
</hibernate-mapping>
child file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.metlife.ins.ereport._2.bi.model.ParameterValue"
table="TRPJOB_RPT_PARM_VAL"
schema="F0654DBA"
>
<meta attribute="class-description" inherit="false">
com.metlife.ins.ereport._2.appl.model.hibernate
</meta>
<meta attribute="implement-equals" inherit="false">true</meta>
<composite-id >
<key-property
name="jobRptParmId"
type="long"
column="JOB_RPT_PARM_ID"
/>
<key-property
name="value"
type="java.lang.String"
column="RPT_PARM_VAL"
/>
</composite-id >
<property
name="displayValue"
type="java.lang.String"
column="RPT_PARM_DSPL_VAL"
/>
<property
name="sortOrder"
type="int"
column="SORT_ORD"
/>
<many-to-one name="parentParam" class="com.metlife.ins.ereport._2.bi.model.Parameter" column="JOB_RPT_PARM_ID" insert="false" update="false">
</many-to-one>
</class>
</hibernate-mapping>
Any help would be greatly appreciated.
thanks
Sai Kiran