Hi,
Since the project I showed you is a commercial one, I made one to demonstrate the bug. The bug seems to appear with many to many relationships. You can download it at:
http://www.geocities.com/danbunea/NHBug.zip
It is built on VS 2005. I have a User and UserGroup classes with a many to many relationship between them. I generate the sql script, the many to many table contains and elt column.
This is the generated script:
create table Users (UserID INT IDENTITY NOT NULL, Version INT not null, Canceled BIT not null, Name NVARCHAR(255) not null, Pass NVARCHAR(255) not null, primary key (UserID))
create table UserGroups (UserGroupID INT IDENTITY NOT NULL, Version INT not null, Canceled BIT not null, Name NVARCHAR(255) not null, Description NVARCHAR(255) not null, primary key (UserGroupID))
create table UsersGroups (GroupID INT not null,
elt INT not null, UserID INT not null)
alter table UsersGroups add constraint FKEC3AF233983803017185C17C foreign key (elt) references Users
alter table UsersGroups add constraint FKEC3AF23398380301 foreign key (elt) references Users
alter table UsersGroups add constraint FKEC3AF2332BE07FEB foreign key (UserID) references UserGroups
alter table UsersGroups add constraint FKEC3AF233284FF848 foreign key (GroupID) references Users
The mapping file for User:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Server.BusinessLayer.BusinessObjects.User, Server" table="Users">
<id name="Id" column="UserID" type="Int32" unsaved-value="0" access="nosetter.camelcase">
<generator class="identity">
</generator>
</id>
<version name="Version" column="Version" type="Int32" access="nosetter.camelcase"></version>
<property name="Canceled" column="Canceled" type="System.Boolean" not-null="true" access="nosetter.camelcase"/>
<property name="Name" column="Name" type="System.String" not-null="true"></property>
<property name="Pass" column="Pass" type="System.String" not-null="true"></property>
<bag name="Groups" table="UsersGroups" lazy="true" cascade="save-update">
<key column="GroupID"/>
<many-to-many class="Server.BusinessLayer.BusinessObjects.UserGroup, Server" />
</bag>
</class>
</hibernate-mapping>
The mapping file for UserGroup:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Server.BusinessLayer.BusinessObjects.UserGroup, Server" table="UserGroups">
<id name="Id" column="UserGroupID" type="Int32" unsaved-value="0" access="nosetter.camelcase">
<generator class="identity">
</generator>
</id>
<version name="Version" column="Version" type="Int32" access="nosetter.camelcase"></version>
<property name="Canceled" column="Canceled" type="System.Boolean" not-null="true" access="nosetter.camelcase"/>
<property name="Name" column="Name" type="System.String" not-null="true"></property>
<property name="Description" column="Description" type="System.String" not-null="true"></property>
<bag name="Users" table="UsersGroups" >
<key column="UserID"/>
<many-to-many class="Server.BusinessLayer.BusinessObjects.User, Server" />
</bag>
</class>
</hibernate-mapping>
I have used NHibernate 1.0.
Thank you,
Dan