Michiel
unread,Jan 26, 2009, 11:31:59 AM1/26/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhusers
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!