-->
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: many-to-many operation
PostPosted: Tue Nov 04, 2003 8:24 am 
Newbie

Joined: Mon Oct 27, 2003 8:15 pm
Posts: 10
Location: Birmingham, AL
I've got a many-to-many association, and I'm not sure where to start. I'm using someone else's database schema that looks like the following:

Foo
int id <--- primary key
int val <---- Second unique key
String Name

Bar
int identifier
String Name

MappingTable
int identifier <----Maps to Bar.identifer
int secondId <---- Maps to Foo.val (!) under the right conditions
int type <---- That's the condition. type must == 1 for a Foo to Bar mapping.

This schema is more complex than I would have made, but allows for the MappingTable to map Bar to more than one table (Foo, Foo1, Foo2) all with int identifiers.

My question is can I produce a Collection mapping that will allow me to one-way map Foo join Bar where MappingTable.type==1? I don't have much control over the schema, but might be able to make a case for multiple association tables. I'm a "simple-as-possible" database guy, so the type in the MTM mapping table isn't my style, but I can certainly understand how it might be someone else's.

The association is so confusing to me that I haven't successfully put a mapping together that makes sense to me. The foreign key value I'm using isn't the primary key for the table, so it's throwing me for a loop.

If it was joining the PK, I'd just use a set

Code:
<class name="Foo" table="foo">
{blah}
<set role="bars" table="mapping_table">
   <key column="secondid"/>
  <many-to-many column="identifier" class="Bar"/>
</set>
{blah}
</class>

But it isn't joined using the PK, and all the wishing in the world won't make it so.

Any suggestions would be greatly appreciated although there's almost no chance of a schema change.


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.