Error when auditing child collection in subclass

Description

If I have three classes: ClassA, ClassB and ClassC where ClassB inherits from ClassA and ClassA has a collection of ClassC objects, when committing an object of type ClassB that has changes to the subclasses collection of ClassC objects, I was getting a type casting error:

Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String, System.Object]' to type ClassC

Environment

None

Attachments

2

Activity

Show:

Devin Michael March 26, 2015 at 4:02 PM

Sorry about that. Thank you for the insight.

Roger March 26, 2015 at 3:34 PM

In your case you have a bidirectional reference without setting inverse="true" on the collection. Any reason why you're using this mapping? To "solve" your issue, simply add inverse="true".
NH Core supports this, yes, but it must be a rare case... Setting low prio on this one.

Devin Michael March 25, 2015 at 9:43 PM

Mapping file that causes issue.

Devin Michael March 25, 2015 at 9:43 PM

I believe I've finally been able to create a minimum mapping and NUnit test for the issue I was having.

Below is a sample HBM mapping that would cause the issue:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"
assembly="NHibernate.Envers.Tests"
namespace="NHibernate.Envers.Tests.NetSpecific.Integration.MultiLevelInheritance">

<class name="Container" table="Containers">
<id name="ContainerID">
<generator class="assigned" />
</id>
<property name="ContainerName" />
<property name="ContainerShortName" />
<bag name="Locations" table="Locations" cascade="all" access="field.pascalcase-m">
<key column="ContainerID" />
<one-to-many class="Location" />
</bag>
<joined-subclass name="ReagentContainer" table="ReagentContainers">
<key column="ContainerID" />
<property name="PassageNumber" />
</joined-subclass>
<joined-subclass name="StorageContainer" table="StorageContainers">
<key column="ContainerID" />
<property name="Active" />
</joined-subclass>
</class>

<class name="Location" table="Locations">
<id name="LocationID">
<generator class="assigned" />
</id>
<many-to-one name="Parent" column="ContainerID" />
<property name="DateLocationEntered" />
<property name="DateLocationExited" />
<many-to-one name="StorageContainer" column="StorageContainerID" />
</class>

</hibernate-mapping>

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created March 11, 2015 at 10:46 PM
Updated March 7, 2017 at 10:00 AM
Resolved March 7, 2017 at 10:00 AM
Who's Looking?