Hello everybody,
I need some help again... :)
I have the following situation in my db (semplified):
Code:
TABLE [Test_Master] (
[Id] [int] NOT NULL ,
[RowVersion] [int] NULL
CONSTRAINT [PK_Test_Master] PRIMARY KEY CLUSTERED
([Id]) ON [PRIMARY]
)
TABLE [Test_Master2] (
[Id] [int] NOT NULL ,
[RowVersion] [int] NULL
CONSTRAINT [PK_Test_Master2] PRIMARY KEY CLUSTERED
([Id]) ON [PRIMARY]
)
TABLE [Test_Tree] (
[Id] [int] NOT NULL ,
[RowVersion] [int] NULL
CONSTRAINT [PK_Test_Tree] PRIMARY KEY CLUSTERED
([Id]) ON [PRIMARY]
)
TABLE [Test_Cross] (
[IdMaster1] [int] NOT NULL ,
[IdMaster2] [int] NOT NULL ,
[RowVersion] [int] NULL
CONSTRAINT [PK_Test_Cross] PRIMARY KEY CLUSTERED
(
[IdMaster1],
[IdMaster2]
) ON [PRIMARY] ,
CONSTRAINT [FK_Test_Cross_Test_Master] FOREIGN KEY
(
[IdMaster1]
) REFERENCES [Test_Master] (
[Id]
),
CONSTRAINT [FK_Test_Cross_Test_Master2] FOREIGN KEY
(
[IdMaster2]
) REFERENCES [Test_Master2] (
[Id]
)
)
TABLE [Test_Cross2] (
[IdMaster1] [int] NOT NULL ,
[IdMaster2] [int] NOT NULL ,
[IdTree] [int] NOT NULL ,
[RowVersion] [int] NULL
CONSTRAINT [PK_Test_Cross2] PRIMARY KEY CLUSTERED
(
[IdMaster1],
[IdMaster2],
[IdTree]
) ON [PRIMARY] ,
CONSTRAINT [FK_Test_Cross2_Test_Cross] FOREIGN KEY
(
[IdMaster1],
[IdMaster2]
) REFERENCES [Test_Cross] (
[IdMaster1],
[IdMaster2]
),
CONSTRAINT [FK_Test_Cross2_Test_Tree] FOREIGN KEY
(
[IdTree]
) REFERENCES [Test_Tree] (
[Id]
)
)
and the related xml file is the following:
Code:
<class name="ObjectModel.Test.Master, ObjectModel" table="Test_Master">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Test</param>
<param name="column">Test_Master</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<bag name="crosses" lazy="true" inverse ="true" cascade="all">
<key column="IdMaster1" />
<one-to-many class="ObjectModel.Test.Cross, ObjectModel" />
</bag>
</class>
<class name="ObjectModel.Test.Master2, ObjectModel" table="Test_Master2">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Test</param>
<param name="column">Test_Master2</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<bag name="crosses" lazy="true" inverse ="true" cascade="all">
<key column="IdMaster2" />
<one-to-many class="ObjectModel.Test.Cross, ObjectModel" />
</bag>
</class>
<class name="ObjectModel.Test.Cross, ObjectModel" table="Test_Cross">
<composite-id>
<key-many-to-one name="Master1" class="ObjectModel.Test.Master, ObjectModel" column="IdMaster1" />
<key-many-to-one name="Master2" class="ObjectModel.Test.Master2, ObjectModel" column="IdMaster2" />
</composite-id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<bag name="cross2s" lazy="true" inverse ="true" cascade="all">
<key>
<column name="IdMaster1" />
<column name="IdMaster2" />
</key>
<one-to-many class="ObjectModel.Test.Cross2, ObjectModel" />
</bag>
</class>
<class name="ObjectModel.Test.Cross2, ObjectModel" table="Test_Cross2">
<composite-id>
<key-many-to-one name="Cross" class="ObjectModel.Test.Cross, ObjectModel">
<column name="IdMaster1" />
<column name="IdMaster2" />
</key-many-to-one>
<key-many-to-one name="Tree" class="ObjectModel.Test.Tree, ObjectModel" column="IdTree" />
</composite-id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
</class>
<class name="ObjectModel.Test.Tree, ObjectModel" table="Test_Tree">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Test</param>
<param name="column">Test_Tree</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<bag name="cross2s" lazy="true" inverse ="true" cascade="all">
<key column="IdTree" />
<one-to-many class="ObjectModel.Test.Cross2, ObjectModel" />
</bag>
</class>
Everything works fine except for the class Cross2:
I executed the application setting show_sql=true: the sql query that NHibernate writes to load Cross2s is correct, it loads correctly each property in the object, but in the Cross (father) class NHibernate sets a collection with count=0:
Code:
protected virtual System.Collections.IList cross2s
{
get
{
if (m_test_cross2s== null)
{
m_test_cross2s=new System.Collections.ArrayList();
}
return m_test_cross2s;
}
set
{
if (value != this.m_test_cross2s)
{
m_test_cross2s = value;
}
}
}
Could someone give me any idea?
Thanks in advance
Antonella