hibernate - NHibernate updates not persisted -


I have two organizations that are declared (very simplified):

  Public test1 {public virtual id (get; set;) public virtual icon & lt; Test 2 & gt; Public Virtual Ent ID (Receive; Set;) Public Virtual Test 1 Generator {Set; Set;} public virtual string name {get; Set;}} & lt; Hibernate-mapping xmlns = "kalash: nhibernate-mapping-2.2" namespace = "test" assembly = "test" & gt; & Lt; Class name = "test1" table = "test1" & gt; & Lt; Id name = "id" column = "id_parent" & gt; & Lt; Generator class = "parent" /> & Lt; / Id & gt; & Lt; Set name = "child" table = "test2" cascade = "save-update" batch-size = "10" inverse = "true" & gt; & Lt; Major column = "id_parent" no-null = "true" /> & Lt; One-to-many classes = "test. Test2, test" /> & Lt; / Set & gt; & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt; & Lt; Hibernate-Mapping XMLNS = "Kalash: Nibinet-Mapping -2.2" namespace = "test" assembly = "test" & gt; & Lt; Class name = "test2" table = "test2" & gt; & Lt; Id name = "id" column = "id_child" & gt; & Lt; Generator class = "parent" /> & Lt; / Id & gt; & Lt; Many-to-one names = "parent" column = "id_parent" class = "test test 1, test" /> & Lt; Property name = "name" column = "name" /> & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;  

Now I want to change the property name of one (first) child:

  var institutions = session. Create Character & lt; Test1 & gt; (). List & lt; Test1 & gt; (); Var tx = session Previous transaction (); Foreach (Test 1 unit in institutions) {entity.Childs.First (). Name = "boobala"; Session.Update (unit); } Tx.Commit ();  

But it does not work, I can see in the NhProf that the transaction was started, SQL parents were fired to attract the records, and the child No other SQL was left to fetch the record but to update the name property. What am I doing wrong? I was trying different things when I was reading the documentation but there was no success.

Thanks a long time ago!

ISession.Update should not be called in the scenario given above Working with the attached unit, the changes are tracked automatically. There is no need to call the update explicitly.

For further explanation, read here:

With this also depends on what is decided upon updating your flushmod. Try to collect your Flushmoda explicitly in the above example. Here is a table of Flushmodes:

Auto
Sometimes the query is indicated after the execution so that the query will never return stale status . This is the default flush mode

comma
When a transaction occurs, the signal is then flown.

never unless flush () is explicitly called by application, it is never flushed. This mode is only very efficient for reading transactions

Then you will end up with something like this:

  session. FlushMode = FlushMode.Commit; Var Institutions = Session Create Character & lt; Test 1 & gt; (). List & lt; Test 1 & gt; (); (Var tx = session.BeginTransaction ()) using {foreach (Test 1 unit in entities) {entity.Childs.First (). Name = "boobala"; Session.Update (unit); } Tx.Commit (); }  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -