nHibernate Mapping issue -- Nulling, not deleting children and grandchildren -



nHibernate Mapping issue -- Nulling, not deleting children and grandchildren -

blockquote

we using bycode method of mapping our data..

i have process (process table) object has list of processstep (processstep table) objects in turn has handbag of processstepuser (processstepuser table) objects assigned each step.

the objects load fine, in web page if delete step collection, rehydrate mvc action process , save process, step in database has processid set null breaks link, leaves step in database , assigned users.

what want able delete step , have processstep , processstepusers deleted.

likewise, when edit processstep (say alter name of step) , save, it's saving that, processstep users nulled out (of processstepid) , recreated, leaving orphaned records.

i have column on processstepuser overall processid well, can prevent user beingness assigned more 1 time step of process.

my relevant mapping follows:

process:

list(x => x.processsteps, m => { m.key(k => k.column("processid")); m.index(i => i.column("steporder")); m.lazy(collectionlazy.nolazy); m.cascade(cascade.all); m.inverse(false); }, r => r.onetomany(o => o.class(typeof (processstep))));

processstep:

bag(x => x.processstepusers, m => { m.key(k => k.column("processstepid")); m.lazy(collectionlazy.nolazy); m.cascade(cascade.all); m.inverse(false); }, r => r.onetomany(o => o.class(typeof (processstepuser)))); manytoone(x => x.process, m => { m.column("processid"); m.class(typeof (process)); });

processstepuser

manytoone(p => p.step, m => { m.column("processstepid"); m.class(typeof (processstep)); }); manytoone(p => p.process, m => { m.column("processid"); m.class(typeof (process)); });

as said, saves fine on creation , loads fine display. dropping of step or editing of step creating havoc in database.

i hacked step deletion process flagging them , manually deleting them before saving process master object, i'd nhibernate if possible.

thanks!

blockquote

first off martin caught 1 issue cascade.all.include(cascade.deleteorphans)... original code had, forgot i'd changed while attempting solve problem.

i rewrote tests , mapping working fine, apologies there. delete question, site not letting me (in firefox) edit...

the problem ended beingness because getting process object database , serializing view json object. passed json object bound process object.

the long , short our repository calling saveorupdate(obj) on object, since had been disconnected, needed phone call merge(obj) did , worked perfectly.

i leave powers whether question has value remaining.

thanks!

try cascade(cascade.alldeleteorphan) on associations want them deleted instead of having other side nulled...

nhibernate nhibernate-mapping mapping-by-code

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -