Error when auditing child collection in subclass
Description
Environment
Attachments
Activity
Patryk Marek March 3, 2017 at 9:10 AM
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>
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