Who is Ali Özgür?

RecentComments

Comment RSS

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
  1. Call a factory method
  2. Create a Curve
  3. Create CurveInterval objects
  4. Put CurveInterval objects inside the Curve.Intervals collection
  5. Call the same factory function to create another Curve instance
  6. Before creating Curve instance I perform some checks with HQL , this causes session to be flushed automaticaly
  7. I get the error when session is about to be flushed automatically

001 <?xml version='1.0' encoding='utf-8'?> 
002
003<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'> 
004
005<class 
006
007name='GradeEntry.Domain.Curve, GradeEntry.Domain' 
008
009      table= 'LetterGrade'> 
010
011<id name='Id' 
012
013column='LG_ID' 
014
015unsaved-value='0'> 
016
017<generator class='native'/> 
018
019</id> 
020
021
022
023<version name='ManagedVersion' column='NhVersion' type="System.Int64" unsaved-value="0"/> 
024
025
026
027<property name='DateCreated'/> 
028
029<property name='CreatedByPersonId'/> 
030
031<property name='Locked'/> 
032
033<property name='LockChangedById' column ='LockChangedByID'/> 
034
035<property name='LockChangedOn'/> 
036
037<property name='LockMessage'/> 
038
039<property name='LogIdx'/> 
040
041<property name='LogCnt'/> 
042
043<property name='IsStable'/> 
044
045
046
047<bag name='Intervals' 
048
049order-by='LetterID asc' 
050
051table='LetterGradeList' 
052
053access='field.camelcase-underscore' 
054
055inverse='true' 
056
057cascade='delete-orphan, save-update' 
058
059lazy='true'> 
060
061<key column='LG_ID'/> 
062
063<one-to-many class='GradeEntry.Domain.CurveInterval, GradeEntry.Domain' /> 
064
065</bag> 
066
067
068
069<bag name='Log' 
070
071order-by='Idx asc' 
072
073table='LetterGradeLog' 
074
075access='field.camelcase-underscore' 
076
077inverse='true' 
078
079cascade='delete-orphan,save-update' 
080
081lazy='true'> 
082
083<key column='LG_ID'/> 
084
085<one-to-many class='GradeEntry.Domain.CurveLog, GradeEntry.Domain' /> 
086
087</bag> 
088
089
090
091</class> 
092
093</hibernate-mapping>
094
095
096

 

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.

  1. I create 2 parent objects save them , flush the session and refresh them
  2. Then for each parent object I create some child objects of type Child1
  3. 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.
  4. 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


Posted in: .NET Development , C# , NHibernate  Tags:

Comments


January 8. 2009 14:03
Busby SEO Test
thanks for that code simply executes and the following steps

   http://intersindo.com/seo-contest/


January 8. 2009 14:18
aliozgur
You are welcome

   http://blog.pragmasql.com/


May 22. 2009 01:06
tukang nggame
great code, thanks.

   http://belajarseo.com/bebas/tukang-nggame-seo-contest.php


June 28. 2009 17:57
tukang nggame
Nice post, thanks…

   http://tukangnggame.marsudiyanto.info/


July 12. 2009 00:42
James H
Interesting post - Just subscribed to your RSS feed.. Thanks

   http://weightloss.jims-info.com/


July 14. 2009 02:55
Marc Ecko
Would you like to post a guest post on my blog?

   http://thewatchshop.biz/


July 17. 2009 19:32
foxy
Wow! Thank you! I always wanted to write in my site something like that

   http://loseweightfastpills.com/


New Zealand Sam
July 18. 2009 08:24
Sam
I have been looking for content like this for a research project I am working. Thanks very much.

   http://makemoneyonline.net.nz/


New Zealand Jay
July 18. 2009 08:24
Jay
I hadn't been using my rss reader for a while and I have a huge backlog of stuff to catch up on. Glad to have taken to time to catch up on your blog though. Cheers.

   http://makemoneyonline.net.nz/


July 19. 2009 19:10
Hoodia Slankepiller
Great write up - Thank you for sharing..

   http://blog.tv2.dk/hoodia_danmark/entry324904.html


July 19. 2009 19:10
Hoodia
Thanks.. Funny, I actually had this on my mind a few days ago..

   http://blog.tv2.dk/hoodia_danmark/


July 19. 2009 22:20
запознанства
Thank you, for this code Smile Cheers!

   http://vipdating.bg/


July 19. 2009 22:20
запознанства
Thank you, for the source Smile Cheers!

   http://vipdating.bg/


July 22. 2009 03:05
Christian Audigier
I don't like your template but your posts are quite good so I will check back!

   http://thewatchdealer.biz/


July 24. 2009 16:46
watch movie online
Funny, I actually had this on my mind a few days ago.

   http://watch-movie-online.org/


July 24. 2009 23:46
moratmarit.com
waiting for your next article, thanks for your info

   http://www.moratmarit.com/


July 26. 2009 16:39
deeper voice
Thank you, for the source Smile Cheers!
I actually had this on my mind a few days ago.

   http://deepervoice101.com/


July 26. 2009 16:40
grow taller

Great write up - Thank you for sharing..
I hadn't been using my rss reader for a while and I have a huge backlog of stuff to catch up on.

   http://howtogrowtaller101.com/

Comments are closed