[英]@MappedSuperclass : Persistent entity should have primary key
I'm working with Spring Data JPA and I'm trying to create 4 different entities that will have exactly the same fields but they will be stored in 4 different tables.我正在使用 Spring Data JPA,我正在尝试创建 4 个不同的实体,这些实体将具有完全相同的字段,但它们将存储在 4 个不同的表中。
This is my key class这是我的重点课程
public class IndexId implements Serializable {
private int seqNo;
private String index;
// getters and setters
}
Then I have the base class:然后我有基类:
@MappedSuperclass
public class BaseIndex {
@Id
@Column(name = "seq_no", nullable = false)
protected int seqNo;
@Id
@Column(name = "index", nullable = false)
protected String index;
@Column(name = "value", nullable = false)
protected String value;
//getters/setters
}
Then my entity that will store in the database:然后我的实体将存储在数据库中:
@Entity
@IdClass(IndexId.class)
@Table(name = "bibliographic_single_index")
public class BibliographicSingleIndex extends BaseIndex implements Serializable { }
This is the error I get: Persistent entity 'BibliographicSingleIndex' should have primary key
.这是我得到的错误:
Persistent entity 'BibliographicSingleIndex' should have primary key
。 I also tried with the properties declared as private
and the articles I see on this subject seem to do the same thing.我还尝试使用声明为
private
的属性,我看到的关于这个主题的文章似乎也做同样的事情。
With these pieces of code is it possible to identify what I'm doing wrong?使用这些代码段是否可以确定我做错了什么?
I believe every entity needs a separate java class for the id class.我相信每个实体都需要一个单独的 java 类作为 id 类。 You wouldn't have the problem with embedded ids I think.
我认为您不会遇到嵌入式 ID 的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.