NHibernate subclass with join table with bag of subclass problem -


hi guys have model of type

public abstract class baseentity {     public guid id {get; set;} }  class entitya : baseentity {     ..other properties..     ilist<entityb> bentities {get; set;} }  class entityb : baseentity {     ..other properties..     entitya owner {get, set;} } 

mapped follow:

  <class name="baseentity" abstract="true" table="tbl_baseentity"          dynamic-insert="true" dynamic-update="true" lazy="true" >     <id name="id"         column="id_entity"         type="guid"         unsaved-value="00000000-0000-0000-0000-000000000000">       <generator class="guid.comb" />     </id>      <discriminator column="etitytype" type="string" force="true" />   </class>  <subclass name="entitya"             extends="baseentity"             discriminator-value="a"             dynamic-insert="true"             dynamic-update="true"             lazy="true">      <join table="tbl_entitya">       <key column="id_entitya" />        ...other mapped properties...        <bag name="bentities" cascade="save-update"            lazy="true" inverse="true" fetch="select" outer-join="true" >         <key column="id_entitya" />         <one-to-many class="entityb"/>       </bag>     </join>   </subclass>  <subclass name="entityb"             extends="baseentity"             discriminator-value="b"             dynamic-insert="true"             dynamic-update="true"             lazy="true">      <join table="tbl_entityb">       <key column="id_entityb" />        ...other mapped properties...        <many-to-one name="owner" not-null="true"                    lazy="proxy" fetch="select" column="id_entitya" />     </join>   </subclass> 

now issue when try insert , cascade new entitya collection of entityb correctly initialized (in terms of bidirectional association) works, when try read entitya.bentities collection got exception states nh execute query. after whatching issue nhprof saw query produced incorrect because nh append column id_entitya base table (which not has column) , not destination joined subclass table. can me prblem? how can avoid behavior? it's possible in nh?

thanks in advance.

we've run same problem here, , colleague of mine found solution:

create many-to-one bi-directional relationship on entityb entitya.

this seems nh figure out fk relationship exists between entitya & entityb, instead of baseentity & entityb.

hope helps.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -