-->
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: one-to-one bidirectional mapping(foreign key as primary key)
PostPosted: Fri Sep 27, 2013 7:01 am 
Newbie

Joined: Thu Dec 15, 2011 3:07 am
Posts: 2
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


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.