-->
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.  [ 3 posts ] 
Author Message
 Post subject: replacing one-to-many by join or subclass mapping
PostPosted: Mon Jan 23, 2006 6:42 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
Hi all,

I'm just wondering if it is possible to define a combined mapping for tables that are in a one-to-many relationship.

What I mean is that I am having let's say a Product table and a ProductDescription table. A Product can have many descriptions and is identified by a productId. A productDescription is having a composite-id (id, country, language).

What I would normally do is define a one-to-many from Product to ProductDescription and a many-to-one as the inverse.

But now I'm wondering if I could combine these to objects in one. I was thinking about something like mapping the productDescription and define a join to the product to include all the product attribute as well. This would keep the object models a lot simpler since I'm having a lot of such relations.

It seems, however, that this ain't working since "the foreign key must have the same number of columns as the primary key".

Also... if it would be possible to define such a mapping.... would it be writable? Since the product table is the base table the entries have to be inserted there before one could insert something into the description table.

Hopeing somebody could give me a quick "Yes... it's possible" or "No.. can't do..."... Longer answer will be appreciated as well ;-)

Thanks a lot!
TJ


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 10:21 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It's not possible with your current configuration. And subclasses can't have different numbers of columns in the key. You could set up mappings for each country/langugage combination, but that is probably not what you want.

The one-to-many/many-to-one approach is probably correct.

Check out the <join> element, as it does something like what you want, but it is still restricted to identical primary key shapes.

If there's a single ProductDescription class and lots of other classes refer to it, you could set up a CompositeUserType for it. Combine that with a <typedef> to a short description, and you can reduce your mappings to something simple like
Code:
<class name="SomethingWithProductDescription">
  ...
  <set name="ProductDescription">
    <key name="ProductId"/>
    <element type="ProductDesc"/>
  </set>
</class>

This solution can't work with bidirectional mappings, unfortunately.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 2:46 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
hmm... I was afraid that it wouldn't be possible.

Would have made my object model a bit easier since no one would have had to deal with the difference of core information and description.

Anyway... since it's not possible I just stick with the one-to-many / many-to one approach...

Thanks alot for verifying my doubts!
TJ


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.