-->
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.  [ 3 posts ] 
Author Message
 Post subject: Recommended interface inheritance strategy?
PostPosted: Thu Jul 07, 2005 1:44 am 
Newbie

Joined: Wed Jun 29, 2005 12:49 pm
Posts: 4
I've been toying with many differnet inheritence strategies today, and I was hoping someone could point me to the Right Way to set it up.

I want a way to flag some classes as having a Calendar. It made sense to use an interface, so I called that Schedulable. Now suppose I have Resource, User, and Room that all need a Calendar. The primary keys are very different for Resource/User/Room.

Here are some solutions I came up with:

1. I was thinking of making a unidirectional one-to-one relationship from the three classes to Calendar:
Code:
                 Calendar             
                    ^                   
                    |
            -----------------
           |        |        |
        Resource   User     Room

But then the Calendar can't go back to say the Resource referencing it.

2. I also tried making the Calendar have a relationship with the Schedulable interface:
Code:
   Calendar----Schedulable             
                    |
            -----------------
           |        |        |
        Resource   User     Room

Then the Resource/User/Room need to do something with the schedulable id, but these classes are pretty much unrelated. I don't want the calendarId to be the primary key for any of the classes.

3. Use a discriminator for an association? This doesn't seem to exist by default in hibernate. For instance:
Code:
CALENDAR
---------------
Calendar ID  | Foreign Key | RelationType
12          |   Jimbo      |  User
13          |  112         | Resource
14          |  H114        | Room


Any recommendations?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 4:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<any>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 8:43 am 
Newbie

Joined: Wed Jun 29, 2005 12:49 pm
Posts: 4
Is this the recommended way to map it? I only ask because the docs seem to steer people away from using it:
Quote:
It is impossible to specify a foreign key constraint for this kind of association, so this is most certainly not meant as the usual way of mapping (polymorphic) associations. You should use this only in very special cases (eg. audit logs, user session data, etc).


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