-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: problem with one-to-many relation ship
PostPosted: Fri Jun 16, 2006 1:28 pm 
Newbie

Joined: Fri Jun 16, 2006 12:04 pm
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 18, 2006 6:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
In the key column that is being updated to null, add 'not-null="true"'.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Same Problem
PostPosted: Fri Nov 14, 2008 7:16 pm 
Newbie

Joined: Thu Jun 26, 2008 5:13 pm
Posts: 5
Hai sai,
I too have same problem with deletion.please let me know if you got any answer to the question.


Top
 Profile  
 
 Post subject: Same Problem
PostPosted: Fri Nov 14, 2008 7:17 pm 
Newbie

Joined: Thu Jun 26, 2008 5:13 pm
Posts: 5
Hai sai,
I too have same problem with deletion.please let me know if you got any answer to the question.I did not understand which key column he specified. to set it as not null.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.