-->
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: one-to-many example
PostPosted: Fri Jan 14, 2005 10:55 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Hibernate version:2.1.7

I have been reading Hibernate in Action also have resarched this forum for some examples of one-to-many. My problem is that on my many side I have a composite key. Here is an example.


This is the many side

Code:
...
<composite-id name="heligpKey">
        <key-property name="subscriberNo" column="SUBNO"/>
        <key-property name="personNo" column="PERNO"/>
        <key-property name="eligStartDate" column="ESTDT" type="java.lang.Integer"/>       
        <key-property name="eligEndDate" column="EENDT" type="java.lang.Integer"/>     
</composite-id>


On my one side I also have composite key..

Code:
<composite-id name="hmembpKey">
    <key-property name="subscriberNo" column="SUBNO"/>
    <key-property name="personNo" column="PERNO"/>
</composite-id>



What is the best approach to mapping this type of relationship? is a one-to-many the best way, parent-child, set....?? Is there an example?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 1:41 pm 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
OK, after much research, reading, more research and even more reading I got it to work. Here is my solution. Simple, once I figured it out.

My mapping in hmembpBean.hbm.xml.....

Code:
.....
<set name="eligSet" lazy="true" inverse="true">
      <key>
          <column name="SUBNO"/>
          <column name="PERNO"/>
     </key>
      <one-to-many class="com.sys.dao.HeligpBean"/>
</set>
.....


My HQL...

Code:
FROM HmembpBean hmembpBean  left join fetch hmembpBean.eligSet eligSet WHERE ....


And "BEHOLD" it works!


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.