NHibernate子类与子类包问题的连接表

NHibernate子类与子类包问题的连接表,nhibernate,nhibernate-mapping,Nhibernate,Nhibernate Mapping,嗨,伙计们 我有一个那种型号的 public abstract class BaseEntity { public Guid Id {get; set;} } class EntityA : BaseEntity { ..other properties.. IList<EntityB> BEntities {get; set;} } class EntityB : BaseEntity { ..other properties.. Ent

嗨,伙计们 我有一个那种型号的

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;}
}
公共抽象类BaseEntity
{
公共Guid Id{get;set;}
}
类EntityA:BaseEntity
{
……其他财产。。
IList benties{get;set;}
}
类EntityB:BaseEntity
{
……其他财产。。
EntityA所有者{get,set;}
}
映射如下:

  <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>

…其他映射属性。。。
…其他映射属性。。。
现在的问题是,当我尝试插入一个新的EntityA并将其与正确初始化的EntityB集合级联(根据双向关联)时,一切正常, 但是当我尝试读取EntityA.Benties集合时,我得到了一个异常,它表明NH可以执行查询。 在与NHProf解决问题后,我发现生成的查询是不正确的,因为NH将列ID_ENTITYA附加到基表(显然没有该列)而不是基表 目标联接子类表。 有人能帮我解决这个问题吗? 我怎样才能避免这种行为? 在NH有可能做到这一点吗


提前感谢。

我最近遇到了同样的问题,为此提交了一个问题:


我最近遇到了同样的问题,为此提交了一个问题:


我们刚刚遇到了同样的问题,我的同事发现了这个解决方案:

在EntityB上创建多对一双向关系返回到EntityA

这似乎有助于NH了解EntityA和EntityB之间存在FK关系,而不是BaseEntity和EntityB


希望这能有所帮助。

我们刚刚遇到了同样的问题,我的同事发现了这个解决方案:

在EntityB上创建多对一双向关系返回到EntityA

这似乎有助于NH了解EntityA和EntityB之间存在FK关系,而不是BaseEntity和EntityB


希望这能有所帮助。

@Diego Mijelshon没有,因为我不知道加入的子类是否具有相同的功能。。在两个表之间生成的派生实体。。我得试试。Thanks@DiegoMijelshon没有,因为我不知道连接的子类是否具有相同的特性。。在两个表之间生成的派生实体。。我得试试。感谢NHUsers用户组中的一位用户回答我的问题,这是一个低优先级的问题。。因此,如果没有其他人要求解决该错误,则不会。如果您尝试用连接的子类来做这件事,那么一切都会成功!。。。。正如NHUsers用户组中的一位回答我的那样,这是一个优先级较低的问题。。因此,如果没有其他人要求解决该错误,则不会。如果您尝试用连接的子类来做这件事,那么一切都会成功!。。。。我必须试一试。。之后我会告诉你这是否是一个可行的解决方案!谢谢,我得试试。。之后我会告诉你这是否是一个可行的解决方案!谢谢