I seem to have a strange outer-join situation going on when trying to map a many-to-many association as follows.
SubProject <-- 0.* -------- 0.*--> AttributeDefinition
When I list the SubProjects I get multiple entries for SubProjects for each AttributeDefinition.
ie if a subProject has 4 AttributeDefinitions, I get 4 copies of the SubProject when I run the following code:
Code:
ICriteria criteria = localSession.CreateCriteria(typeof (SubProject));
criteria.Add(Expression.Eq("Project", project));
criteria.AddOrder(Order.Asc("Name"));
results = criteria.List();
Does anyone have any ideas as to how to fix this knotty problem?
I have mapped the relationship as follows:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="KBR.LAPD.DocumentManagement.Entities.SubProject, Entities" table="SUB_PROJECT">
<id name="SubProjectID" column="SUB_PROJECT_ID">
<!--
..... other properties
-->
<bag name="AttributeDefinitions" table="SUB_PROJ_ATTR_DEF" lazy="false" fetch="join" outer-join="false" inverse="true">
<key column="SUB_PROJ_ID"/>
<many-to-many class="KBR.LAPD.DocumentManagement.Entities.AttributeDefinition, Entities" column="ATTR_DEF_ID" outer-join="false" />
</bag>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="KBR.LAPD.DocumentManagement.Entities.AttributeDefinition, Entities" table="ATTR_DEF">
<!--
... other properties
-->
<bag name="SubProjects" table="SUB_PROJ_ATTR_DEF" outer-join="false">
<key column="ATTR_DEF_ID " />
<many-to-many class="KBR.LAPD.DocumentManagement.Entities.SubProject, Entities" column="SUB_PROJ_ID" />
</bag>
</class>
</hibernate-mapping>