aspose file tools*
The moose likes Object Relational Mapping and the fly likes One-to-many mapping and composite key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "One-to-many mapping and composite key" Watch "One-to-many mapping and composite key" New topic
Author

One-to-many mapping and composite key

Bikram Sinha
Greenhorn

Joined: Sep 19, 2008
Posts: 2
I have some issue with the One-to-many mapping and composite key.

I have a table PropT - Parent

column prop_nbr (PK)

Table PropRoleUserT - Child

Composite PK ( prop_nbr , role_nm)

This has a FK for prop_nbr with PropT.prop_nbr

In both the table prop_nbr is not null.

The issue is when I update a data in both parent and child , it is updating the parent , but it is also updating the child for prop_nbr as null and getting the Not null exception. I am not sure why is it updating the prop_nbr in PropRoleUserT to null when I am sending the data.

I want an immediate help.

I am using the XML mapping from Hibernate 3.0 and not POJO.

Here are my mappings :

PROPT
----------

<?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 entity-name="PropT" table="PROP_T" schema="SYSTEM">
<id name="propNbr" type="long" column="PROP_NBR" length="19">
<generator class="sequence">
<param name="sequence">PROP_T_SEQ</param>
</generator>
</id>
<property name="bpmProcessId" type="string"
column="BPM_PROCESS_ID" length="100" />
<property name="dueDt" type="date" column="DUE_DT" length="7" />
<property name="prodDescr" type="string" column="PROD_DESCR"
length="255" />
<property name="propDescr" type="string" column="PROP_DESCR"
length="255" />
<property name="recipientNm" type="string" column="RECIPIENT_NM"
length="100" />
<property name="recvdDt" type="date" column="RECVD_DT"
length="7" />
<property name="senderNm" type="string" column="SENDER_NM"
length="255" />

<!-- Associations -->
<!-- bi-directional many-to-one association to PropNotificationT -->
<set name="propNotificationTs" inverse="false" lazy="true">
<key>
<column name="PROP_NBR" /><!-- a foreign key in PROP_NOTIFICATION_T referencing the primary key of this table. -->
</key>
<one-to-many entity-name="PropNotificationT" />
</set>
<!-- bi-directional many-to-one association to PropRoleUserT -->
<set name="propRoleUserTs" inverse="false" lazy="true">
<key>
<column name="PROP_NBR" /><!-- a foreign key in PROP_ROLE_USER_T referencing the primary key of this table. -->
</key>
<one-to-many entity-name="PropRoleUserT" />
</set>
<!-- bi-directional many-to-one association to StatTypT -->
<many-to-one name="statTypT" class="StatTypT" lazy="proxy">
<column name="STAT_TYP_NBR" not-null="true" length="22" />
</many-to-one>

</class>
<query name="get.proposal.data.by.proposalId">
<![CDATA[
from PropT as prop where prop.propNbr = roposal_id]]>
</query>
</hibernate-mapping>

PropRoleUserT
-------------------------


<?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
entity-name="PropRoleUserT"
table="PROP_ROLE_USER_T"
schema="SYSTEM"
>
<composite-id>
<key-property
name="activeDirNm"
type="string"
column="ACTIVE_DIR_NM"
length="30"
/>
<key-property
name="propNbr"
type="integer"
column="PROP_NBR"
length="7"
/>
<key-property
name="roleNm"
type="string"
column="ROLE_NM"
length="50"
/>
</composite-id>

<!-- Associations -->
<!-- bi-directional many-to-one association to PropT -->
<!-- many-to-one
name="propT"
class="PropT"
update="false"
insert="false"
lazy="proxy"
>
<column name="PROP_NBR" not-null="true" length="7"/>
</many-to-one //-->

</class>
</hibernate-mapping>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One-to-many mapping and composite key
 
Similar Threads
Please suggest on this Mapping
Hibernate Association
Hibernate Association
Integrity constraint violation: for Hibernate Insert
Hibernate- one-to-many association on a foreign key