JPA映射和继承

时间:2017-08-22 16:07:48

标签: java hibernate jpa

我有JPA的映射问题

@Entity
@Table(name = "TBL_A")
public class EntityA {

  // Other mappings

  @OneToMany(mappedBy = "entityA")
  private List<EntityBImpl> bEntities;

  @OneToMany(mappedBy = "entityA")
  private List<AnotherEntityBImpl> anotherBEntities;
}

@Entity
@DiscriminatorValue("X")
public class EntityBImpl extends AbstractEntityB {

  // Other mappings
}

@Entity
@DiscriminatorValue("Y")
public class AnotherEntityBImpl extends AbstractEntityB {

  // Other mappings
}


@Entity
@Table(name = "TBL_B")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "PROJ_TYPE")
public abstract class AbstractEntityB {

  // Other mappings

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ENTITY_A_ID")
  private EntityA               entityA;
}

它在运行时抛出以下异常:

org.hibernate.AnnotationException:mappedBy引用一个未知的目标实体属性:com.example.EntityA.bEntities中的com.example.EntityBImpl.entityA

如何在不改变继承策略的情况下解决问题?

0 个答案:

没有答案