-->
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: <many-to-one> relationships inside <join table>s
PostPosted: Wed Dec 28, 2005 7:12 am 
Newbie

Joined: Mon Dec 26, 2005 12:00 pm
Posts: 8
Hello,

Here's my scenario: I'm working with a legacy database, where inheritance was implemented using both table-per-class and table-per-subclass schemas. In other words, there's always a discriminator column in "super" tables, even where the hierarchy can be completely recovered using joins.

So, I've decided that the best strategy is to use the table-per-class schema and adopt <join table...> tags to "emulate" table-per-subclass when applicable. Generically:

Code:
<class ...>
    <id ..../>
    <discriminator .../>
    <join table=...>
        <key .../>
        <property .../>
        ...
    </join>
</class>


So far, so good. But...

I've noticed that Hibernate (ver. 3.1 and below) doesn't support <many-to-one> relationships inside joined tables.

  1. Why?

    (Performance? Postponed feature? Gotchas?)
  2. How to circumvent this limitation?

    My first tought was to implement a class to represent the "extra" data (i.e., the data of the joined table, including collections) and link it to the main entity with one-to-one relationship. To make this transparent, I'd implement getters/setters in the main entity that just redirect calls to extraData.get... and extraData.set... .

    However, it seems that I'm adapting my entity model to the persistence layer, which sounds strange at first.

    I'd like to hear developers that have faced this situation before...


Also, I see that this is an open issue since nov/04 (Issue #HHH-36), but there hasn't been any comments since then.

Thanks in advance,

_________________
Best regards,
Vilar Camara Neto

(please, don't forget to vote...)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 8:55 am 
Newbie

Joined: Mon Dec 26, 2005 12:00 pm
Posts: 8
I'm deeply sorry: the problem isn't with <many-to-one> tags, but with <one-to-many>, which defines collections.

_________________
Best regards,
Vilar Camara Neto

(please, don't forget to vote...)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 7:42 am 
Newbie

Joined: Mon Dec 26, 2005 12:00 pm
Posts: 8
Weel, the solution couldn't be easier. The <one-to-many> must be outside the <join> element.

This question is over.

_________________
Best regards,
Vilar Camara Neto

(please, don't forget to vote...)


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.