Hi,
I have to develop a small application (.NET) on an legacy database
using nhibernate-mapping. Untill now my development works quite well
and my nhibernate-mappings are fine.
Now I am looking for a nhibernate mapping solution for an m:n-
relationship between two classes. Of course there are three tables in
the database a, b and ab. The last one is used for representing the
n:m relationship between a and b. In my object model I have two
classes A and B. An instance of Class A may have many instances of
class B and vice versa (n:m).
The mapping complications I am confronted result from the database.
Both tables a and b own a composite key composed from two columns
each. Columns a1 and a2 are key columns in table a. Table b uses
columns b1 and b2 as key columns. Table ab has only three columns:
ca1, cb1 and cc. ca1 is part of table a key, cb1 is part of table b
key. The third column cc is shared between both tables a and b.
My idea to map my classes A and B was this following
<class name="A" table="a" ... >
<composite-id>
<key-property name="A1"/>
<key-property name="A2"/>
</composite-id>
.....
<bag name="Bs" table="ab">
<key>
<column name="ca1"/>
<column name="cc"/>
</key>
<many-to-many class="B">
<column name="cb1" />
<column name="cc" />
</many-to-many>
</bag>
</class>
But this doesn't work. I've got the following exception: "Repeated
column in mapping for collection."
In the hibernate-reference 3.3.1 (not in nhibernate) this situation is
mapped using a formula-tag in the many-to-many node. But "formula" is
not a subelement in Namespace 'urn:nhibernate-mapping-2.2.
The example in the hibernate reference is the following:
<class name="User" table="`User`">
<composite-id>
<key-property name="name"/>
<key-property name="org"/>
</composite-id>
<set name="groups" table="UserGroup">
<key>
<column name="userName"/>
<column name="org"/>
</key>
<many-to-many class="Group">
<column name="groupName"/>
<formula>org</formula>
</many-to-many>
</set>
</class>
Is there a similar nhibernate-mapping I can use for my problem? Should
i better resolve the problem in two 1:n relations?
Thank you for every hint.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---