Hi Friends,
I have Two classes two Tables
Code:
[b]Customer :[/b]
customer_id ( PK )
customer_name
[b] CustomerDetails :[/b][code][/code]
customer_id ( PK + FK )
customer_address
The primary key of the Customer Table is the primary and foreign key in the Customer Details.
Code:
public class Customer{
private int customerId;
private String name;
private CustomerDetails customerDetails;
}
public class CustomerDetails{
private int customerId;
private String address;
private Customer customer;
}
Code:
<hibernate-mapping>
<class name="vo.Customer" table="CUSTOMER" >
<id name="customerId" type="int">
<column name="CUSTOMER_ID" />
<generator class="sequence">
<param name="sequence">CUSTOMOER_ID_SEQUENCE</param>
</generator>
</id>
<property name="name" type="String">
<column name="CUSTOMER_ADDRESS"/>
</property>
[color=#BF8000]<one-to-one name="customerDetails" property-ref="customer" constraint="false" class="vo.CustomerDetails" />[/color]
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="vo.CustomerdDetails" table="CUSTOMER_DETAILS">
<id name="customerID" type="int">
<column name="CUSTOMER_ID" />
<generator class="foreign">
<param name="property">customer</param>
</generator>
</id>
<property name="address" type="String">
<column name="CUSTOMER_ADDRESS"/>
</property>
<one-to-one name="customer" constrained="true" cascade="all" />
</class>
</hibernate-mapping>
Friends, my problem is I am not able to do bi-directional one-to-one ( using the foreign key as primary key ) mapping using XML mapping configuration.
Please help me how to do the bi-directional one-to-one ( using the foreign key as primary key ) mapping using XML mapping configuration.
LINK ::
http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html_single/#assoc-bidirectional-121