-->
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.  [ 4 posts ] 
Author Message
 Post subject: Connecting arbitrary objects using a Set
PostPosted: Tue Jan 06, 2009 5:18 am 
Newbie

Joined: Tue Jan 06, 2009 5:08 am
Posts: 10
Hello,
I'm fairly new to hibernate and have a "probably" simple question.
For my project I have a simple class hierarchy:

Code:
abstract class PersistentObject {
Long id;
Set<PersistentObject> connections;
}

class Address extends PersistentObject {
}

class Appointment extends PersistentObject {
}


Now I want to be able to link arbitrary objects (Address -> Address, Address -> Appointment, Address -> AnotherObject, ...) with each other and store them inside the set. I do not want to specifiy an association table for each connection type.
In SQL I would think, I need another table containing the following columns:

Code:
LINK_TABLE
---------------------------------
TABLENAME1 | ID1 | TABLENAME2 | ID2


Is there a way to represent that using hibernates <set> ? I'll probably need a composite key, but since the name of the class isn't part of the class itself, hibernate doesn't allow it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 4:05 am 
Newbie

Joined: Tue Jan 06, 2009 5:08 am
Posts: 10
Does anybody have any idea? Still waiting for a small hint (any hint would be great) at how to do it


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 6:27 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can use the <many-to-any> mapping. Its like the <any> mapping but can be used in a <set>. See http://www.hibernate.org/hib_docs/v3/re ... anymapping.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:42 am 
Newbie

Joined: Tue Jan 06, 2009 5:08 am
Posts: 10
Thank you.
Using many-to-any works fine using a type="uuid" as the key for the table, since I do not need the originating table name.

But if I want to include that too? Can I specifiy this in the <key>-Tag?


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