-->
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: many-to-many with alternate join column?
PostPosted: Sun May 20, 2012 12:02 pm 
Newbie

Joined: Thu Jul 21, 2011 11:41 am
Posts: 5
I've inherited a database model that I'm slowly mapping with Hibernate. I've come across a many-to-many relationship I'm having a lot of difficulty mapping.

Table FOO:
foo_id (pkey)
other_id (int)
...

Table BAR:
bar_id
...

Table FOO_BAR
other_id
bar_id


The issue is that the many-to-many mapping table uses a different column - one that is guaranteed unique but NOT the primary key of the table - when creation the relationship between the two records.

The problem is that Hibernate using this type of property:

Code:
<bag name="bars" table="FOO_BAR">
  <key column="other_id" />
  <many-to-many class="xyz.Bar" column="bar_id" />
</bag>


The Hibernate SQL generated will always use the primary key of the FOO table rather than the FOO.other_id which is what I need. I've tried various approaches to this and I'm unable to get this to work (short of creating a VIEW on top of the FOO_BAR table that resolves other_id to the foo_id).

This can be read-only, I just want to be able to model this correctly. I should be able to specify the join-column somewhere, but it doesn't seem clear to me where I can...


Top
 Profile  
 
 Post subject: Re: many-to-many with alternate join column?
PostPosted: Tue May 22, 2012 9:47 am 
Newbie

Joined: Thu Jul 21, 2011 11:41 am
Posts: 5
So there is no way to specify a column that isn't the primary key to be used in a many-to-many relationship?

For now I've been forced to make the column available using a view. I don't like this approach, but this seems like a significant hole in Hibernate's ability to model database relationships. I realize that ideally we'd have a mapping table that leverages primary keys, but that's not always the case.


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.