I discovered this problem while developing a new system with the latest NHibernate.Burrow distribution (which in turn uses the latest NHibernate distribution). I spent some time Googling around to check if anyboy else met the same problem and found some entries but none of them specified exactly why this failure was happening and how we can solve this problem.
The Problem
My code simply executes the following steps
-
Call a factory method
- Create a Curve
- Create CurveInterval objects
- Put CurveInterval objects inside the Curve.Intervals collection
- Call the same factory function to create another Curve instance
- Before creating Curve instance I perform some checks with HQL , this causes session to be flushed automaticaly
- I get the error when session is about to be flushed automatically
001 <?xml version='1.0' encoding='utf-8'?>
002<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
003<class
004name='GradeEntry.Domain.Curve, GradeEntry.Domain'
005 table= 'LetterGrade'>
006<id name='Id'
007column='LG_ID'
008unsaved-value='0'>
009<generator class='native'/>
010</id>
011
012<version name='ManagedVersion' column='NhVersion' type="System.Int64" unsaved-value="0"/>
013
014<property name='DateCreated'/>
015<property name='CreatedByPersonId'/>
016<property name='Locked'/>
017<property name='LockChangedById' column ='LockChangedByID'/>
018<property name='LockChangedOn'/>
019<property name='LockMessage'/>
020<property name='LogIdx'/>
021<property name='LogCnt'/>
022<property name='IsStable'/>
023
024<bag name='Intervals'
025order-by='LetterID asc'
026table='LetterGradeList'
027access='field.camelcase-underscore'
028inverse='true'
029cascade='delete-orphan, save-update'
030lazy='true'>
031<key column='LG_ID'/>
032<one-to-many class='GradeEntry.Domain.CurveInterval, GradeEntry.Domain' />
033</bag>
034
035<bag name='Log'
036order-by='Idx asc'
037table='LetterGradeLog'
038access='field.camelcase-underscore'
039inverse='true'
040cascade='delete-orphan,save-update'
041lazy='true'>
042<key column='LG_ID'/>
043<one-to-many class='GradeEntry.Domain.CurveLog, GradeEntry.Domain' />
044</bag>
045
046</class>
047</hibernate-mapping>
048
049
050
First Attempt To Reporoduce The Problem
I have prepared a sample project but I was not able to recreate the bug, and I know it is hard to tell what is the problem under these conditions. But I have some more findings about this issue.
- When I replace cascade of the bags to 'all-delete-orphan' from 'delete-orphan,save-update' everything is ok
- When I replace cascade of the bags to 'all, delete-orphan' from 'all-delete-orphan' I still get the assertion failure.
I think the problem is with the new implementation of cascade which is intended to support comma seperated list of cascade options.
Second Attempt To Reporoduce The Problem
After spending some more time trying to diagonise the problem I finally succeeded to reprouce the problem with atest case. I attached the test case.
Simply the problem resolves to something like this.
NOTE: All classes utilize managed versioning by defining ManagedVersion.
- I create 2 parent objects save them , flush the session and refresh them
- Then for each parent object I create some child objects of type Child1
- I perform HQL to get all Child3 instances. Child3 class does not have any association or cascade relation with Parent, Child1, Child2 and ParentRef classes. The HQL I performed causes the session to auto flush thus inserting Child1 instances to the database. But somehow while auto flushing the session versions of the parent objects are not updated. I expect two updates to be submitted to the database for parent objects since we associated Child1 instances with the parents and that must cause a version increment on parent objects.
- Then I try to perform another HQL query to get list of ParentRef objects and I get assertion failure. Note that ParentRef class is associated with Parent class which in turn defines cascade for Children1 and Children2 collections.
If we do not perform the HQL in step 3 Child1 instances will be inserted to the database and parent objects will be updated while performing the HQL in step 4 and we will not get the assertion failure.
I covered both cases in the attached test case.
Database scripts are included under DBScript folder.
Download test case
Requirements
Watch This
See Also
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5