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?