-->
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.  [ 5 posts ] 
Author Message
 Post subject: Ternary Association Design
PostPosted: Fri Feb 27, 2004 7:14 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Hi guys,

I'm using latest version of Hibernate

here's what I wanna do and how I figure out I should implement the mapping:

I have a bottom-up approach in my app, this is why i'm starting from the Tables

I want to have a table A that can have a reference to B OR C.
As I don't wan't to use nullable FK, i'm using an association that is composed of (ID_A, TYPE, ID), Type being B or C.

It works fine from a relational point of view.
Now the Hibernate documentation on ternary associations is rather slim... so I need some help on this point!

How shall I best implement the corresponding mapping?
What are the possibilities offered by Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 8:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
What are the possibilities?
- B referenced by A
- C referenced by A
- B and C referenced by A
- neither B nor C referenced by A


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 10:23 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
It's a mutually exclusive OR:

A can reference B OR C, but neither both nor none

I figured out I probably should be using the <any> attribute. like this:

<any name="BorC" id-type="long" meta-type="class">
<column name="TYPE"/>
<column name="ID"/>
</any>

but the doc specifies "You should use this only in very special cases (eg. audit logs, user session data, etc)." which sound bizarre to me since i've got several cas like that in my CDM.

And I can't understand wht I shall do with meta-type attribute. Example are not meaningful to me.

And then I don't know how to use this in a ternary association, it remains very fuzzy to me whether to use <index-many-to-many> <many-to-many> or <set> or... and how hibernate is gonna behave after that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 10:32 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about saying that a is abstract and b and c inherit a ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 10:53 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Hum, whould have beeb nice, but it's not possible here, it's to very different object (say USER and EXPENSE!)

But I needed this stuff, I carrefully read the Inheritance Mappings chapter and had a successful implementation of table-per-subclass. Amazing! It works so well...

Here I indeed have ... say an EXPENSE that can be related to say a USER or a COMPANY....
I actually have 2 tables. COMPANY_EXP and USER_EXP, but since they contains exactlly the same fields it's not a good design. I could have two nullable FK, but it's not good either.

THe proper way to implement this is really to have this association.
I'm sure some already faced this issue. But I keep not understanding the few sentences in the Ternay Associations Chaprter:

"One approach is to use composite elements (discussed below). Another is to use a Map with an association as its index."
That's really to short for me...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.