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: Mapping parent entities without separate table
PostPosted: Mon Jun 20, 2005 3:54 pm 
Beginner
Beginner

Joined: Wed May 25, 2005 7:49 pm
Posts: 25
How would I go about mapping a table like this:
Code:
ITEM_ID | GROUP_ID
------------------
1       | A
2       | A
3       | B
4       | B


Items 1 and 2 would belong to the parent entity Group A, while items 3 and 4 would belong to the parent entity Group B. I am stumped on how to do this without a lot of subselecting / exotic SQL. Any help would be appreciated!

Hibernate version: 3.0.5


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 5:42 pm 
Beginner
Beginner

Joined: Wed May 25, 2005 7:49 pm
Posts: 25
By the way, the only way I could figure out how to do it is this:
Code:
<hibernate-mapping>
   <class name="Item" table="items">
      <id name="id" column="item_id" />
      <many-to-one name="group" column="group_id" />
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="Group">
   <subselect>select distinct group_id from items</subselect>
      <id name="id" column="group_id"/>
      <set name="children" >
         <key column="group_id"/>
         <one-to-many class="Item"/>
      </set>
   </class>
</hibernate-mapping>


I was just wondering if there is a more elegant way to do this, i.e. without the subselect.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.