-->
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: OR advice
PostPosted: Mon Dec 08, 2003 10:59 pm 
Newbie

Joined: Mon Dec 08, 2003 1:54 pm
Posts: 4
About three days of research has resulted in my concluding that I have no hope of doing this correctly the first time. I'm asking for advice on how to handle this OR mapping: A table, we'll call MAP, is used to relate the PKs for any two tables. Each row is assigned a discriminator. Therefore, three columns;

Code:
MAP table:
------------
TYPE varchar (PK)
FROM varchar (PK)
TO   varchar



Similar patterns appear often when integrating systems; it's too painful or simply impossible to alter some production system to create proper foreign keys, yet one must record that a row was created on behalf of another row, possibly on a different platform. So, you define a TYPE and store the primary key of one table in FROM and the primary key of another table in TO. Multiple TYPEs may exist (possibly for the same pair of tables...) In our case TYPE and FROM form a composite key and the MAP table may provide many-to-one relations (otherwise this could be a many-to-many junction table.)

Given a pair of tables that are related via MAP...

Code:
TABLE_A table:
--------------
ID number (PK)

TABLE_B table:
--------------
ID number (PK)



...we'll define a MAP discriminator 'FOO' that identifies MAP rows like so:

Code:
x = some primary key value from TABLE_A
y = some primary key value from TABLE_B
INSERT INTO MAP (type, from, to) VALUES ('FOO', x, y)



Given that MAP rows which relate TABLE_A and TABLE_B will always have TYPE = 'FOO', how does one model the association in Hibernate?

Should I subclass a MAP base class by the discriminator? Will having the discriminator in the key "work" with Hibernate (2.1)? May I then associate TABLE_A and TABLE_B to the subclasses via; <many|one-to-one><column...></>?

I've tried various forms of composite-id keys on MAP and so far I've been unable to figure out how to associate this to TABLE_A or TABLE_B. The notion of a constant (for the TYPE) as a property appears to be persona non grata in Hibernate.

How would you approach this and can you point to any examples? I feel I've put in the requisite time trying to figure this out, and I'd like to make use of Hibernate, but I need to get past this quandary without too much more time spent experimenting.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 12:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This looks like a standard <many-to-any> association, if I'm not mistaken...


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.