I have a tbale Roles, with columns Id, Name, Description and RoleType.
The last columns determines the class, possible values are
SecurityGroup and Permission.

My mapping looks like this:

<class name="Role" table="Roles">
    <id name="Id" type="Int32" unsaved-value="0">
        <generator class="native"/>
    </id>
    <discriminator column="RoleType" type="String"/>
    <property name="Name" type="String" length="50"/>
    <property name="Description" type="String" length="250"/>
    <subclass name="Permission" discriminator-value="Permission"/>
    <subclass name="SecurityGroup" discriminator-value="SecurityGroup"/
>
</class>

There's an abstract Role class that defines the properties Name and
Description, and classes SecurityGroup and Permission that inherit
from the Role class.

I also have a User class and corresponding table, as well as a many-to-
many mapping between users and roles. For this purpose the User class
has 2 properties of type IList<SecurityGroup> and IList<Permission>.
The mapping for the User class looks like this:

<class name="User" table="Users">
    <id name="Id" column="Id" type="Int32" unsaved-value="0">
        <generator class="native"/>
    </id>
    <property name="Username" type="string" length="50"/>
    <property name="HashedPassword" column="Password" type="string"
length="50"/>
    <bag name="SecurityGroups" table="Users_Roles" cascade="all-delete-
orphan" lazy="false">
        <key column="UserId"/>
        <many-to-many class="SecurityGroup" column="RoleId"/>
    </bag>
    <bag name="Permissions" table="Users_Roles" cascade="all-delete-
orphan" lazy="false">
        <key column="UserId"/>
        <many-to-many class="Permission" column="RoleId"/>
    </bag>
</class>

When I try session.Get<User>(id) I get the following exception:

XunitException: NHibernate.WrongClassException : Object with id: 1 was
not of the specified subclass: SecurityGroup (loading object was of
wrong class [Permission])

What could be the problem?

Thanks for looking!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to