-->
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: additional column at many-to-many association table
PostPosted: Wed Sep 24, 2003 7:09 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
I'd like to implement a typical M-to-N relationship, like book borrowing
Code:
user -> borrow <- book
           |
       borrowDate

where borrowDate should be an attribute in borrow table.
I manage to implement the M-to-N between user and book as:
Code:
<class name="Book" table="book">
   <id name="id" column="id" type="int" unsaved-value="0" >
      <generator class="assigned"/>
   </id>
   <set name="borrowers" table="borrow" inverse="false" cascade="none">
      <key column="bookId"/>
      <many-to-many class="User" column="borrowerId"/>
   </set>
</class>

<class name="User" table="user">
   <id name="id" column="id" type="int" unsaved-value="0" >
      <generator class="assigned"/>
   </id>
   <set name="borrowedBooks" table="borrow" inverse="false" cascade="none">
      <key column="borrowerId"/>
      <many-to-many class="Book" column="bookId"/>
   </set>
</class>


but have no idea on dealing with the borrowDate. Any clue?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2003 7:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
use a composite-element mapping


Top
 Profile  
 
 Post subject: ...
PostPosted: Thu Sep 25, 2003 2:18 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
i changed the M-N to two 1-M and explicitly create the <class> and Java class for the relation. It works fine, though a little troublesome.

Is this the appropriate approach in handling this? I'm wondering is there any better solution for it...


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.