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!?