Fluent NHibernate subclass reference -
so have following entities:
timelinerecord:     id: pk     from: datetime     to: datetime  servicerecord extends timelinerecord:     id: pk     timelinerecord_id: fk     somespecificproperties...  demand:     id: pk     from: datetime     to: datetime     ...  servicedemandconnection:     id: pk     service: servicerecord     demand: demand   timelinerecord, demand , servicedemandconnection mapped using classmap id(x => x.id). servicerecord mapped using subclassmap (table-per-class). references in servicedemandconnection mapped using references(x => x.service).cascade.none() , same .demand.
the problem inserting servicedemandconnection set servicerecord , demand. error: detail=key (servicerecord_id)=(8) not present in table "servicerecord". error states true. 8 id of timelinerecord, not servicerecord. however, id of servicerecord (timelinerecord_id, not mapped/not accessible in code) should used instead. current mapping hides servicerecord.id.
how should tell nhibernate use id of subclass table (servicerecord), , not of base class table (timelinerecord)? nhibernate creates proper constraint in database, during runtime violates somehow.
you need either
- map 
servicerecordseparate class not usingsubclassmapuse it'sid - or use 
idbase class , not map insidesubclassmap 
the second approach works because subclassmap creates fk relationship between child , parent object data consistent , have 
timelinerecord   id : pk  servicerecord extends timelinerecord:   timelinerecord_id: fk -----> timelinerecord.id   it still valid point references child classess.
Comments
Post a Comment