-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with many-to-many relationship - mapping
PostPosted: Mon Nov 22, 2010 5:16 pm 
Newbie

Joined: Mon Nov 22, 2010 2:58 pm
Posts: 1
Hello,

i want to have a many-to-many relationship between two tables - normaly the resulting table for
the relationship exists of the primary keys of the two tables. But I want also to add the primary
foreign of the two tables.

For a better unterstanding:

Code:
tbl_document_template
----------------------
documentTemplateId (PK)
documentTypeId (PF)
name
description
...



Code:
tbl_template_element
----------------------
templateElementId (PK)
documentTypeId (PF)
name
value
......



And the table for the many-to-many relation look like this:

Code:
tbl_document_template_element
-----------------------------
templateElementId (PF)
documentTemplateId (PF)
documentTypeId (PF)


I have no problem with the mapping of the first two tables, when the resulting table only consist of the
two primary foreign keys (templateElementId, documentTemplateId).

Here I have the mapping for the template_element object
for the many-to-many relationship:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                           namespace="Core.Domain.Model"
                           assembly="Core">

  <class name="DocumentTemplate" table="tbl_document_template" dynamic-update="true">
    <cache usage="read-write"/>
    <id name="DocumentTemplateId" column="DocumentTemplateId" type="int">
      <generator class="identity"/>
    </id>
   
    <property name="Name" length="50"/>
    <property name="Description" length="255"/>
    <property name="CreationDate" type="datetime" update="false"/>
    <property name="UpdateDate" type="datetime"/>

   
    <many-to-one name="DocumentType" column="DocumentTypeId" class="DocumentType" cascade="save-update"/>
   
    <bag name="TemplateElements" table="tbl_template_element_tbl_document_template" lazy="false" >
      <key >
        <column name="documentTemplateId"/>
      </key>
      <many-to-many class="TemplateElement" column="templateElementId" ></many-to-many>
    </bag>

  </class>
</hibernate-mapping>


I tried a couple of hours - but I don't know how to modify this hbm so that also the documentTypeId
is stored in the tbl_document_template_element, when I want to assign a template_element to a document_template

I hope someone could help me with this issue!?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.