c# - Adding and saving not persistent objects to persistent object in NHibernate -


could explain me?

i have standard relations in mssql db:

[item] id symbol  [item_version] id item_id (fk) symbol 

in [item] mapping there standard item_version bag cascade="all" , many-to-one in [item_version] mapping.

this test case:

    [test]     public void addnewversiontopersistentobject()     {         //creating item         item = new item();         i.symbol = "item 1 symbol";              //saving item         item.dao.save(i);         long id = i.id;          //clearing session , getting item db         datahelper.daofactory.clearsession();         item itemfromdb = item.dao.getbyid(id);          //creating new versions         itemversion v1 = new itemversion();         v1.symbol = "version 1 symbol";          itemversion v2 = new itemversion();         v2.symbol = "version 2 symbol";          //adding versions , saving item         itemfromdb.additemversion(v1);         itemfromdb.additemversion(v2);         item.dao.saveorupdate(itemfromdb);           //clearing session, getting item , checking results         datahelper.daofactory.clearsession();         item itemfromdb2 = item.dao.getbyid(id);         assert.areequal(2, itemfromdb2.itemversions.count);     } 

test fails, when adding new itemversion objects item object taken db (as coded above).

when add new itemversions new item, , call save on item - works fine. why that?

save/update/delete/etc methods not persist changes database; queue actions in unit of work (the session)

in fact, don't need call of them modify persistent objects: happens automatically on flush (which, btw, shouldn't call explicitly: use transaction instead)

more info: http://nhibernate.info/doc/nh/en/index.html#manipulatingdata


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -