1

我有一个父类:

@MappedSuperclass
public class BaseText implements Serializable {

    @Column(name = "LOCALE_CODE", nullable = false)
    private String localeCode;

    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @Index
    @Column(name = "LOCALIZED_TEXT_ID", nullable = false)
    @ForeignKey
    private LocalizedText localizedText;

    //getters and setters 
}

和子类之一:

@Entity
@Table(name = "ASSESSMENT_TEXT")
@AttributeOverride(name = "localeCode", column = @Column(name = "LOCALE_CODE"))
@AssociationOverride(name = "localizedText", joinColumns = @JoinColumn(name = "LOCALIZED_TEXT_ID"))
public class AssessmentText extends BaseText {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @Index
    @Column(name = "ASSESSMENT_ID", nullable = false)
    @ForeignKey
    private Assessment assessment;

    //Getters and setters.
}

当我试图持久化一个对象时,我收到以下错误:

org.apache.openjpa.persistence.ArgumentException: Superclass field "java.lang.Object.localizedText" is mapped in the metadata for subclass "com.my.com.AssessmentText", but is not a persistent field.

是什么导致了这种情况以及如何解决?

我在 JUnit 中使用嵌入式 derby 数据库,JPA 实现是 OpenJPA。

4

2 回答 2

0

我不确定它是否是解决方案,但我错过了来自 AssessmentText 的 @Inheritance 注释:

@Entity
@Table(name = "ASSESSMENT_TEXT")
@Inheritance(strategy=InheritanceType.JOINED)
@AttributeOverride(name = "localeCode", column = @Column(name = "LOCALE_CODE"))
@AssociationOverride(name = "localizedText",
                     joinColumns = @JoinColumn(name = "LOCALIZED_TEXT_ID"))
public class AssessmentText extends BaseText {
于 2013-01-02T17:01:29.250 回答
0

我有同样的问题,并通过将 MappedSuperClass 添加到 persistence.xml 来解决它。

我知道这也在某处的评论中,但有用的被隐藏了,我认为这应该是一个答案,而不是对该问题的评论。

于 2016-07-21T08:18:51.220 回答