c# - NHibernate: Stateful and Stateless sessions need different mappings -
i'm using fluent nhibernate read , write files. @ moment, have parent-child relationship, mappings defined by
public class parentmappings: classmap<parent> { public parentmappings() { table("parent"); id(x => x.id).column("parent_id"); ... hasmany(x => x.children) .not.keynullable() .not.inverse() .keycolumn("parent_id") .cascade.all(); ... } }
and
public class childmappings : classmap<child> { public childmappings() { table("child"); id(x => x.id).column("child_id"); map(x => x.parentid).column("parent_id"); ... } }
here problem. want able write parent/child table stateless session, preserve speed, read table stateful session, children collection gets loaded correctly. however, seems 2 approaches incompatible. call hasmany()
breaks statless write; removing breaks stateful read.
in wider context, there may instances i'll want write database using stateful session. in case inclusion of map(x => x.parentid).column("parent_id")
statement breaks stateful write.
it looks though i'll need use different mappings stateful , stateless sessions. however, i'm new nhibernate, , can't see obvious way @ stage. can suggest way this, or equivalent workaround?
you have mapped backreference parent in child should reference not id alone. change to
// in childmap reference(x => x.parent).column("parent_id");
and can set inverse enhance performance
// in parentmap hasmany(x => x.children) .not.keynullable() .inverse() .keycolumn("parent_id") .cascade.all();
then hasmany
, map(x => x.parentid)
not collide anymore in stateful session
Comments
Post a Comment