单表继承中的JPA关系

时间:2015-07-27 16:39:33

标签: java spring jpa eclipselink

设置是JPA / Eclipselink 2.6; Spring JPA 4.1.6 以下实体:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(...)
public class Mother implements Serializable {
//...
}

儿童

@Entity
@DiscriminatorValue(...)
public class Child extends Mother{
  @Basic(optional = false)
  @NotNull
  @JoinColumn(referencedColumnName = "id", name = "another_entity_id", updatable=false)
  @ManyToOne(fetch = FetchType.EAGER, optional = true)
  private AnotherEntity anotherEntity;

//... getter,setters, the works
}

现在,如果我使用JpaRepository或JpaRepository saveAndFlush,它会从属性而不是注释(在本例中为anotherEntity而不是another_entity_id)中猜测名称,这显然会失败;另外,如果我设置属性名称以匹配列名,它会抱怨我想在整数列中保存bytea(对象)。

看起来像个错误,对吧?

0 个答案:

没有答案