-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need Help With Mapping 1:M/M:1 Via a Link Table?
PostPosted: Wed Aug 22, 2007 8:18 am 
Newbie

Joined: Tue Jul 26, 2005 10:25 am
Posts: 12
I have two classes, Project and Memo. Each Memo is associated with one Project, but a Project can have several Memos.

So, Project has a one-to-many relationship with Memo, and Memo has a many-to-one relationship with Project.

In the database schema, T_PROJECTS and T_MEMOS are connected via T_PROJECT_MEMO_LINK (PROJECTID and MEMOID).

Since this is a 1:M/M:1 via a link table, what would the mapping look like?

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 10:09 am 
Newbie

Joined: Wed Aug 24, 2005 1:43 pm
Posts: 10
Hi Jason,
one solution is to add a link class in between.

in the Memo class:
<many-to-one name="projectMemoLink" class="ProjectMemoLink" column="xxx" not-null="true" insert="false" update="false"/>

in the ProjectMemoLink class:
<many-to-one name="project" column="xxx" not-null="true"/>
<many-to-one name="memo" column="xxx" not-null="true"/>

and in the Project class:
<bag name="projectMemoLinks" lazy="false" inverse="true" cascade="all-delete-orphan">
<key column="xxx" not-null="true"/>
<one-to-many class="ProjectMemoLink"/>
</bag>

The Link class can be helpful if you need to store extra stuff like update date or update user id.

hope that helps,
Seb


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