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: Many-to-Many with additional column in relationship table?
PostPosted: Mon Nov 14, 2005 9:22 am 
Newbie

Joined: Mon Nov 14, 2005 8:49 am
Posts: 3
Hello,

I try to incorporate into Hibernate since several weeks, and i hardly got it. But there's a important silly thing that i don't understand:

I defined three tables: task, parameter and task_parameter, which represents the relationship between task and parameter.

(task) 1 ----- n (task_parameter) n ------ 1 (parameter)

So far, so good.

But now i need to save an additional property for every relation of tasks and parameters. In the database design i solved this common issue with an additional column in task_parameter.
But how can i map this with Hibernate?

Thanks for every thought!

Greetings,

Simon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 10:01 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
If I understand you correctly, you only have two classes in Java up to now.

In order to specify additional information on the relationship, you have to create a third class representing the relationship and therefore the table task_parameter.
Then you simply convert your many-to-many mapping to two one-to-many mappings (and perhaps the corresponding many-to-one-mappings in the new class).

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 10:11 am 
Newbie

Joined: Mon Nov 14, 2005 8:49 am
Posts: 3
Heinz,

thanks for your reply. I expected the solution you posted, but i thought there is a way to represent the relation without an additional class that will clutter my clean design ;o)...

Anyway - thanks!

Simon


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 11:32 am 
Beginner
Beginner

Joined: Sat Oct 29, 2005 2:05 am
Posts: 21
Location: Kansas City, KS
Alternatively, you can use the approach described here:
http://www.hibernate.org/118.html#A11

"I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?"


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.