-->
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.  [ 1 post ] 
Author Message
 Post subject: One-to-many mapping with composite key
PostPosted: Wed Jul 01, 2009 11:21 am 
Newbie

Joined: Wed Apr 08, 2009 6:59 am
Posts: 4
I've been trying to figure out this mapping all day and I just can't get it right. I've been reading up on all kinds of similar problems but just can't seem to apply the same to my specific example.

Here's my model (this is a legacy model, which I cannot change):

One 'Type' can have many 'Codes'.

Type:
#TYPE_ID
TYPE_CATEGORY

Code:
#CODE_CATEGORY
#CODE_ID

I want a list of Codes attached to a Type - I need to look up all the codes in the Code table that have the same category.

After trying many different configurations, here's my mapping:
Code:
     
<bag name="categories" cascade="none" lazy="false">
    <key foreign-key="TYPE_CATEGORY">
        <column name="CODE_CATEGORY"/>
        <column name="CODE_ID"/>
    </key>
    <one-to-many class="com....Code" />
</bag>


But my categories collection is always empty, even if data exists that should be found.

The complicating factors here seem to be:
  • There's a missing link table, category should be an entity in it's own right, but it's existence is not explicit even though it is being used to link the entities Type and Code
  • Code has a composite key
  • The columns that are supposed to be matched (TYPE_CATEGORY and CODE_CATEGORY) are not named the same, and I can't find a way to correctly express the link of TYPE_CATEGORY and CODE_CATEGORY in the mapping.

Does anyone have any idea how this can be mapped? I know this is one of those poor designed, legacy schema situations, but it doesn't seem too uncommon and I've certainly seen hibernate deal with worse.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.