Issues

Select view

Select search mode

 
50 of 95

InvalidCastException from FindDirty on many-to-one association with property-ref to composite-id class

Fixed

Description

When one class (A) references another (B) using a composite-id, through a many-to-one association with a property-ref, all operations appear to work normally except for the update – which fails on the call to FlushDirty on A with a new reference to a B (either new or existing B). It seems as if the flush dirty ignores the property-ref association and attempts to ascertain whether the property is dirty by comparing the property-ref's actual value (which is an integer) to the new B's composite identifier.

I will attach a test ASAP.

Error:

NHibernate.Test.NHSpecificTest.NH1234.BugTestCase.PropertyRefCompositeIdDoesNotFlushProperlyOnUpdate:
System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'NHibernate.Test.NHSpecificTest.NH1234.WidgetCategory'.

See:

http://groups.google.com/group/nhusers/browse_thread/thread/36085e43e5a65698/fd7a90465de1f1e3?lnk=gst&q=finddirty#fd7a90465de1f1e3

Tested with SQLite ADO.Net provider (found on ms sql 2005)

Environment

None

Attachments

1

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created April 22, 2013 at 4:05 PM
Updated May 1, 2017 at 3:42 AM
Resolved February 22, 2015 at 2:19 AM

Activity

Show:

Alex ZaytsevMay 1, 2017 at 3:42 AM

Closing issues resolved in 4.1.0

Jeff KeyserSeptember 9, 2014 at 12:28 PM

A pull requests with a proposed fix for this issue exists on NH-3480.

AntonApril 22, 2013 at 5:39 PM

Complete "working" failing test is attached now.

AntonApril 22, 2013 at 5:37 PM

Failing test

AntonApril 22, 2013 at 4:05 PM

We are using Composite keys for now, and preparing move to GUID instead of composite keys.
For transition period we are using "many-to-one" associations with "property-ref"
All classes with composite-id cannot be assigend because of Update error described here in this case.

So, I assume we have same bug.
Creation, Deletion works fine, just Update fails.
Here some mapping examles:

<class table="Direction">
<composite-id access="field">
<key-property name="idBase" column="id_base" />
<key-property name="idDirection" column="id_direction" />
</composite-id>
<property name="GUID" column="guid" />
</class>

<class table="t_PromoEventPeriods" name="DirectionRefferer">
<id name="GUID" column="GUID" />
<many-to-one name="Direction" column="guid_Direction" fetch="select" property-ref="GUID" lazy="proxy" />
</class>

Here, for example, we can CREATE new DirectionRefferer with Direction assigned by "property-ref many-to-one association", is successfully inserts to database
But, when we try to UPDATE DirectionRefferer with any other instance of Direction assigned to corresponding field - so we have error:

System.InvalidCastException : Unable to cast object of type 'System.Guid' to type 'Direction'.

Who's Looking?
Loading...