-->
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.  [ 2 posts ] 
Author Message
 Post subject: Example: One to many & Many to One..
PostPosted: Fri May 05, 2006 8:10 am 
Newbie

Joined: Fri Apr 28, 2006 6:14 am
Posts: 8
Hi All,

Can anyone send me a sample example for Hibernate One to many & Many to One..
Also, if there are any links, from where i can download the example, please point me to that..

Thanks a lot,
Shridhar..


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 1:42 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Code:
<?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 package="learn.hibernate">   
   <class name="ClassA" table="A">   
     <id name="aId" type="long" column="a_id" />
     <property name="aProperty" column="a_prop" />
     <set name="bSet"
          lazy="true"
          inverse="true"
          cascade="all-delete-orphan">
       <key>
          <column name="a_id" />
       </key>
       <one-to-many class="learn.hibernate.ClassB"/>
      </set>
   </class>
</hibernate-mapping>


Code:
<?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  package="learn.hibernate">
   <class name="ClassB" table="B">
      <composite-id>
         <key-property name="bIdOne" column="b_id" />
         <key-property name="bIdTwo" column="a_id" />
      </composite-id>
      <property name="bProperty" column="b_prop" />
      <many-to-one name="aObject"
                   class="learn.hibernate.ClassA"
                   column="a_id"
                   insert="false" update="false"/>
   </class>
</hibernate-mapping>



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

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.