-->
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: Mapping a "multivalued" ternary association
PostPosted: Tue Aug 17, 2004 9:14 am 
Newbie

Joined: Tue Aug 17, 2004 8:51 am
Posts: 2
Hibernate version: How to detect it?

I do not know how to map the following: a "chat" is associated with 0..n "users" via 0..m "roles", mulitple "users" for a "chat" and a "role".

In Java I have
Code:
class Chat {
  protected Map roleUsers;
}

which holds a Set of "User"s for each "Role".

In the DB I would expect a table (chat_id, role_id, user_id) with all three fields being the primary key.

But how to map it?
TIA,
Albrecht[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 7:06 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
I can tell you a way to map it if you like, bit it's probably not what you're thinking about.

If I were mapping this, unless there were some other reason I couldn't (that you haven't mentioned), I'd model the relationship class explicitly.

That is, I'd have a class named something like ChatUserRoleRelationship.
It's look something like
Code:
class ChatUserRolRelationship {
  protected Chat chat;
  protected User user;
  protected Role role;
}

I don't think this class is exactly what you want, but I hope you get my drift.

This is the way I model pretty much all of the many-many relationships on our project, ternary or otherwise.

Yes, it results in an extra class, but if you name it right, it won't confuse your codebase and it actually makes things much easier for the non-hibernate-guru developers on your project to understand.

I think what you want to do is also doable without an explicit class modelling the relationship, but someone else will have to explain it for you (I haven't even read the relevant manual section).



_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 9:52 am 
Newbie

Joined: Tue Aug 17, 2004 8:51 am
Posts: 2
Thank you. I did something like you have told me (i.e. using an additional, "technical" entity) by using an entitiy "UserSet" as the value side of the map.

If I ever run into any problems with this approach I will rethink if your solution would be a better solution. Surely, it is a more general one.

Regards,
Albrecht


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.