nhibernate - Ruling out NHiberate mappings causing deletion of entity -
i have nhibernate issue update entity , causes deletion of entity. set of entities , related mappings large replicate here wanted create sample data in order discuss issue. in cut out example imagine updating d results in deletion of a.
q: fair impossible mapping issue given mapping files related a ie (bmappingfile & cmappingfile) have mapping a set .cascade.none() or there other nhib config/mapping related setting should aware of achieve behaviour?
db tables
a
aid | aname
b
bid | bname | aid
c
cid | cname | aid
d
did | dname | cid
and set of corresponding mapping files along lines of
amappingfile
public amap() { table("[dbo].[a]"); lazyload(); cache.readwrite().includeall(); id(x=>x.aid) .access.camelcasefield(prefix.underscore) .column("[aid]") .generatedby.identity(); hasmany(x=>x.bs) .access.camelcasefield(prefix.underscore) .cascade.alldeleteorphan() .fetch.select() .inverse() .lazyload() .keycolumns.add("[aid]") .cache.readwrite().includeall(); hasmany(x=>x.cs) .access.camelcasefield(prefix.underscore) .cascade.alldeleteorphan() .fetch.select() .inverse() .lazyload() .keycolumns.add("[aid]") .cache.readwrite().includeall(); ... }
bmappingfile
public bmap() { table("[dbo].[b]"); lazyload(); cache.readwrite().includeall(); id(x=>x.bid) .access.camelcasefield(prefix.underscore) .column("[bid]") .generatedby.identity(); references(x=>x.a) .access.camelcasefield(prefix.underscore) .cascade.none() .fetch.select() .columns("[aid]"); ... }
cmappingfile
public cmap() { table("[dbo].[c]"); lazyload(); cache.readwrite().includeall(); id(x=>x.cid) .access.camelcasefield(prefix.underscore) .column("[cid]") .generatedby.identity(); references(x=>x.a) .access.camelcasefield(prefix.underscore) .cascade.none() .fetch.select() .columns("[aid]"); hasmany(x=>x.ds) .access.camelcasefield(prefix.underscore) .cascade.alldeleteorphan() .fetch.select() .inverse() .lazyload() .keycolumns.add("[did]") .cache.readwrite().includeall(); ... }
dmappingfile
public dmap() { table("[dbo].[d]"); lazyload(); cache.readwrite().includeall(); id(x=>x.did) .access.camelcasefield(prefix.underscore) .column("[did]") .generatedby.identity(); references(x=>x.c) .access.camelcasefield(prefix.underscore) .cascade.none() .fetch.select() .columns("[cid]"); ... }
you should provide snippet of code or queries question.
i have nhibernate issue update entity , causes deletion of entity
suppose persisted a
-entity instance collection of 5 b
. once update instance of a
using empty collection of bs
b
s removed.
Comments
Post a Comment