-->
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: conditional Parent/Child mapping
PostPosted: Wed Jul 18, 2007 10:25 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
Ok,

I know there must be an easy solution to this, but it is beyond me at the moment. Here are my entities, pretty basic:

Item (1) --> (0..*) Photo

Profile (1) --> (0..*) Photo


So both Item and Profile have a one-to-many association to Photo, originally I had a table called ItemPhoto and a table called ProfilePhoto, but when I attempted to map this, I got a duplicate mapping exception and realized I wasn't able to do this as both mapping files would be mapping the Photo entity, only with different table names.

How would I map this in the DB? Make two subclasses for Photo and do a table-per-subclass? That seemed a little cumbersome just to get the mapping to the db.

I know there must be a simple solution, i've just stared at it for too long =P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 3:01 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
Code:
Item:
...
   <set name="photos" inverse="true">
       <key column="item_id" />
       <one-to-many class="package.ItemPhoto" />
   </set>
...

Profile:
...
   <set name="photos" inverse="true">
       <key column="profile_id" />
       <one-to-many class="package.ProfilePhoto" />
   </set>
...


if you want bidirectional, put a one-to-one in photo classes as well:

Code:
ItemPhoto:
...
   <many-to-one name="item" class="package.Item" column="item_id" />
...

ProfilePhoto:
...
   <many-to-one name="profile" class="package.Profile" column="profile_id" />

...


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.