Hi, i have a very strange problem:
I have 2 class (
AlertS and
AlertP) inherit from a base class:
Code:
<class name="Alert" table="Alert">
<id name="ID" column="Id">
<generator class="native" />
</id>
<discriminator column="Type" type="string"></discriminator>
<subclass name="AlertS" discriminator-value="S">
</subclass>
<subclass name="AlertP" discriminator-value="P">
</subclass>
</class>
Then i have a class
BContract inherit from
Contract (table per class Hierarchy) another:
Code:
<class name="Contract" table="Contracts">
<id name="ID" column="Id">
<generator class="native" />
</id>
<discriminator column="TypeC" type="string"></discriminator>
<set name="AlertSc" lazy="true" table="Alert" generic="true" inverse="true" cascade="all-delete-orphan">
<key column="Code" />
<one-to-many class="AlertS" />
</set>
<subclass name="BContract" discriminator-value="ASS">
<set name="AlertPr" lazy="true" table="Alert" generic="true" inverse="true" cascade="all-delete-orphan">
<key column="Code" />
<one-to-many class="AlertP" />
</set>
</subclass>
</class>
Contract have a collection of
AlertS and
BContract a collection of
AlertP, when i try to load the second collection i obtain an exception:
Nhibernate.WrongClassException: "Failed to lazily initialize a collection" -
{"Object with id: 1 was not of the specified sublcass: Test.AlertP (loading object was of wrong class [Test.AlertS])"}
The sql statement, which nhibernate use to load Alert collection object do not use the discriminator value!
Thank for any suggestion