I'm sorry,
I have already posted a question about this (
http://forum.hibernate.org/viewtopic.php?t=960551) but I need to solve the problem and it seems very strange.
I have semplified my tables structure with respect to last topic.
I can write in Table3 table but I cannot load the records from it. It seems a bug because I cannot load data with that structure only, a composite id containing 3 key fields.
Debugging the code I have observed that NHibernate loads the Table3 single items but when it assigns the bag collection to the property in the Table2 object the collection is empty (count = 0).
Maybe something is wrong in my xml structure?
Code:
CREATE TABLE [dbo].[Test_Table1] (
[Id] [int] NOT NULL ,
[Description] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[RowVersion] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test_Table1] ADD
CONSTRAINT [PK_Test_Table1] PRIMARY KEY CLUSTERED
(
[Id]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Test_Table2] (
[IdTable1] [int] NOT NULL ,
[IdTable2] [int] NOT NULL ,
[Description] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[RowVersion] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test_Table2] ADD
CONSTRAINT [PK_Test_Table2] PRIMARY KEY CLUSTERED
(
[IdTable1],
[IdTable2]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test_Table2] ADD
CONSTRAINT [FK_Test_Table2_Test_Table11] FOREIGN KEY
(
[IdTable1]
) REFERENCES [dbo].[Test_Table1] (
[Id]
)
GO
CREATE TABLE [dbo].[Test_Table3] (
[IdTable1] [int] NOT NULL ,
[IdTable2] [int] NOT NULL ,
[IdTable3] [int] NOT NULL ,
[Description] [nvarchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[RowVersion] [int] NULL ,
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test_Table3] ADD
CONSTRAINT [PK_Test_Table3] PRIMARY KEY CLUSTERED
(
[IdTable1],
[IdTable2],
[IdTable3]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test_Table3] ADD
CONSTRAINT [FK_Test_Table3_Test_Table21] FOREIGN KEY
(
[IdTable1],
[IdTable2]
) REFERENCES [dbo].[Test_Table2] (
[IdTable1],
[IdTable2]
)
GO
Code:
<!-- TABLE 1 -->
<class name="ObjectModel.Test.Table1, ObjectModel" table="Test_Table1">
<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="table2s" inverse="true" cascade="all" lazy="true">
<key column="IdTable1" />
<one-to-many class="ObjectModel.Test.Table2, ObjectModel" />
</bag>
</class>
<!-- TABLE 2 -->
<class name="ObjectModel.Test.Table2, ObjectModel" table="Test_Table2">
<composite-id>
<key-many-to-one name="Table1" class="ObjectModel.Test.Table1, ObjectModel" column="IdTable1" />
<key-property name="IdTable2" type="Int32" />
</composite-id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<property name="Description" column="Description" type="String" />
<bag name="table3s" inverse="true" cascade="all" lazy="true">
<key>
<column name="IdTable1" />
<column name="IdTable2" />
</key>
<one-to-many class="ObjectModel.Test.Table3, ObjectModel" />
</bag>
</class>
<!-- TABLE 3 -->
<class name="ObjectModel.Test.Table3, ObjectModel" table="Test_Table3">
<composite-id>
<key-many-to-one name="Table2" class="ObjectModel.Test.Table2, ObjectModel">
<column name="IdTable1" />
<column name="IdTable2" />
</key-many-to-one>
<key-property name="IdTable3" type="Int32" />
</composite-id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<property name="Description" column="Description" type="String" />
</class>