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 servicerecord separate class not using subclassmap use it's id
  • or use id base class , not map inside subclassmap

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

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -