What happens is, if an existing object that has a list of other items (stored in another table with FK to main table) and you add an item to that list, and then directly save it without any other changes to the object. Then the addition to the list does not get saved!
Only if you also change a property on the main object, then the additions to the list are saved
Example: Order contains OrderLines When I add an OrderLine without modifying the Order object, the added orderline is not saved.
I added a testproject with unit-test to prove the problem. Used: SQL: MS SQL 2008 Version NHibernate: 3.3.2.4000
PS. database is not added to the sample project.
Environment
None
Attachments
3
Activity
Show:
Oskar Berggren
September 7, 2014 at 3:14 PM
I dunno... It seems like it should be made to work with FlushMode.Auto.
David Perfors
August 21, 2014 at 8:34 AM
I found this issue again and saw it was still open. After some testing I found that with a bit more transaction management and proper use of flush, everything works as it should be.
Since I don't have the possibility to close this issue myself, I want to request that someone who can will close this issue...
Paul Comsup
September 2, 2013 at 7:10 AM
I just tried with the various flush modes, and none of them were able to retrieve the lines with the refresh.
Using session.Flush() however does fix the problem, so then we will have to use that.
But still to me it seems that the Refresh could handle this...
Ricardo Peres
August 30, 2013 at 1:51 PM
No, really don't think so... if you are using FlushMode.Committed, NHibernate will only send changes to the database when the session is committed. If you use FlushMode.Always you will get the behavior you want, but its generally not recommended, because NHibernate has to check potentially lots of entities all the time (before issuing queries).
Paul Comsup
August 30, 2013 at 12:04 PM
Apparently, you also seem to have thought that it should...
What happens is, if an existing object that has a list of other items (stored in another table with FK to main table) and you add an item to that list, and then directly save it without any other changes to the object.
Then the addition to the list does not get saved!
Only if you also change a property on the main object, then the additions to the list are saved
Example:
Order contains OrderLines
When I add an OrderLine without modifying the Order object, the added orderline is not saved.
I added a testproject with unit-test to prove the problem.
Used:
SQL: MS SQL 2008
Version NHibernate: 3.3.2.4000
PS. database is not added to the sample project.