-->
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: doubt in one-to-one association mapping
PostPosted: Sat Apr 03, 2010 4:17 am 
Newbie

Joined: Sat Apr 03, 2010 3:57 am
Posts: 1
Hi,
I'm relatively new to Hibernate and I'm having lot of confusions with mappings:
Tables:
Code:
CREATE TABLE CUSTOMER_MASTER (CUST_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,CUST_FIRST_NAME VARCHAR(20) NOT NULL , CUST_LAST_NAME VARCHAR(20) NOT NULL);

CREATE TABLE CUSTOMER_DETAILS (CUST_DETAIL_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,CUST_ID INT NOT NULL,CUST_ADDRESS VARCHAR(100) NOT NULL,CUST_PHONE VARCHAR(20) NULL, CUST_ZIP INT NULL, CUST_AGE INT NOT NULL,FOREIGN KEY(CUST_ID) REFERENCES CUSTOMER_MASTER(CUST_ID) ON DELETE CASCADE);



mapping:
Code:
   <class name="MedCustomer" table="CUSTOMER_MASTER">
      <id name="custID" column="CUST_ID" unsaved-value="0">
         <generator class="increment" />
      </id>
      <property name="custFirstName" column="CUST_FIRST_NAME" />
      <property name="custLastName" column="CUST_LAST_NAME" />
      <one-to-one name="custDetail" class="CustomerDetail" cascade="all" ></one-to-one>
   </class>
   <class name="CustomerDetail" table="CUSTOMER_DETAILS">
      <id name="custDetailID" column="CUST_DETAIL_ID">
         <generator class="increment"></generator>
      </id>
      <property name="custID" column="CUST_ID" />
      <property name="custAddress" column="CUST_ADDRESS" />
      <property name="custPhone" column="CUST_PHONE" />
      <property name="custZip" column="CUST_ZIP" />
      <property name="age" column="CUST_AGE" />
   </class>

1) Is there a way to persist the class MedCustomer and CustomerDetail without having a link in CustomerDetail class for seting parent's ID .. like:
Code:
public int getCustID() {
   return customer.getCustID();
}
public void setCustID(int custID) {
   this.custID = customer.getCustID();
}


2) Incase I try to load all the MedCustomer .the join happens between CUSTOMER_MASTER.CUST_ID and CUSTOMER_DETAILS.CUST_DETAIL_ID , which is incorect. How to overcome this proeblem?


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.