-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with one to many relationship
PostPosted: Tue May 13, 2008 3:22 pm 
Newbie

Joined: Mon May 12, 2008 12:16 pm
Posts: 7
I am trying to map a one to many and many to many relation of Customer, Contact and Address. I have many to many relation with Customer and Address. one to many with Customer and Contact.
Each time I insert a record, I get three PK from a sequence. Say e.g. 11 for Customer, 12 for Address and 13 for Contact, For Address and Contact these keys are correct in both parent and child tables.
For Customer I dont know where the heck a key 14 is generated as PK, But in child tables Cust_id (FK to contact and address) is remain 11.

Please suggest me if there is something wrong with mapping. Also using hibernate should i setup the RI contraints in DB or in my mapping files.

Mapping Files are;

Customer:
------------

<?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>
<class
name="com.wonder.common.Customer"
table="CUSTOMER">
<id
name="id"
type="long"
column="CUST_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="fName">
<column name="FIRST_NAME" />
</property>
<property name="lName">
<column name="LAST_NAME" />
</property>
<property name="gender">
<column name="GENDER" />
</property>
<property name="businessTitle">
<column name="BUSINESS_TITLE" />
</property>
<property name="customerNumber">
<column name="CUST_NO" />
</property>
<property name="regDate">
<column name="REG_DATE" />
</property>
<set
name="contact"
cascade="save-update,persist">
<key
column="CUST_ID"
not-null="true" />
<one-to-many
class="com.wonder.common.Contact"
entity-name="CustContacts" />
</set>
<set
name="address"
table="CUST_ADDRESS"
cascade="save-update,persist">
<key column="CUST_ID" not-null="true"/>
<many-to-many
column="ADDRESS_ID"
class="com.wonder.common.Address" />
</set>
</class>
</hibernate-mapping>


Contact:
---------

<?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>
<class
name="com.wonder.common.Contact"
entity-name="EmpContacts"
table="EMP_CONTACT">
<id
name="id"
type="long"
column="CONTACT_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="homePhone">
<column name="HOME" />
</property>
<property name="officePhone">
<column name="OFFICE" />
</property>
<property name="mobile">
<column name="MOBILE" />
</property>
<property name="fax">
<column name="FAX" />
</property>
<property name="email">
<column name="EMAIL" />
</property>
</class>

<class
name="com.wonder.common.Contact"
entity-name="CustContacts"
table="CUST_CONTACT">
<id
name="id"
type="long"
column="CONTACT_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="homePhone">
<column name="HOME" />
</property>
<property name="officePhone">
<column name="OFFICE" />
</property>
<property name="mobile">
<column name="MOBILE" />
</property>
<property name="fax">
<column name="FAX" />
</property>
<property name="email">
<column name="EMAIL" />
</property>
</class>
</hibernate-mapping>


Address
----------

<?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>
<class
name="com.wonder.common.Address"
table="ADDRESS">
<id
name="id"
type="long"
column="ADDRESS_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="Type">
<column name="TYPE" />
</property>
<property name="Street">
<column name="STREET" />
</property>
<property name="Road">
<column name="ROAD" />
</property>
<property name="City">
<column name="CITY" />
</property>
<property name="Postcode">
<column name="POSTCODE" />
</property>
<property name="Country">
<column name="COUNTRY" />
</property>
</class>
</hibernate-mapping>

_________________
Thanks in Advance
Kashif


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.