简体   繁体   English

@MappedSuperclass :持久化实体应该有主键

[英]@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.

相关问题 Hibernate 持久化实体应该有一个主键 - Hibernate persistent entity should have a primary key 持久实体“*******”在@Entity 类中应该有主键错误 - Persistent entity '*******' should have primary key error in @Entity class 具有复合主键的实体类没有getter和setter - Entity class with a composite primary key doesn't have getter and setter @Entity 无法识别 @MappedSuperclass 中的 @Id - @Entity not recognizing the @Id in a @MappedSuperclass 我已经使用 PartitionKey 注释声明了主键,但仍然得到 Entity Order 没有声明主键 - I have declared primary using PartitionKey annotation but still getting Entity Order does not declare a primary key @MappedSuperclass 不是 JPA 中的 @Entity 吗? - @MappedSuperclass is not an @Entity in JPA? 在jpa实体中设置外键时出错:您无法刷新与非托管对象具有持久关联的非托管对象… - Error setting foreign key in jpa entity: You cannot flush unmanaged objects… that have persistent associations to unmanaged objects 如何映射主键组件和外键具有相同列名的Hibernate实体? - How to map Hibernate entity where a primary key component and the foreign key have the same column name? 如何为没有主键或唯一键列的表创建 JPA 实体 - How to create a JPA entity for a table that doesn't have a Primary Key or Unique Key column 没有主键ID的实体 - Entity without Primary Key ID
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM