简体   繁体   English

多个 spring 引导实体上的自动增量 ID

[英]Auto Increment Id on multiple spring boot entity

I have 3 class in my spring boot application and in all of these 3 classes i am using a vaiable sNo (serial No) which is primary key of that table我的 spring 启动应用程序中有 3 个 class,在所有这 3 个类中,我使用的是可变的 sNo(序列号),它是该表的主键

After running spring boot application a domain hibernate_sequence is automatically created in database which contains运行 spring 引导应用程序后,会在数据库中自动创建域 hibernate_sequence,其中包含

+----------+
| next_val |
+----------+
|     1    |
|     1    |
|     1    |
+----------+

Now i am using one end point for saving some users in my db.现在我正在使用一个端点来保存我的数据库中的一些用户。 For example i save 3892 rows(records) in my users table after that my hibernate_sequence contains.例如,在我的 hibernate_sequence 包含之后,我在我的用户表中保存了 3892 行(记录)。

+----------+
| next_val |
+----------+
|     3893 |
|     3893 |
|     3893 |
+----------+

Now suppose i want to save one row in application table then serial number is now starting from 3894.现在假设我想在应用程序表中保存一行,那么序列号现在从 3894 开始。

How i manage or control this auto increment serial number in my multiple spring boot entity?我如何在我的多个 spring 引导实体中管理或控制此自动递增序列号?

@Entity
@Table(name = "users")
class User {
    @Id
    @NotNull
    @GeneratedValue
    Long sNo
    // Rest of the fields
}

    @Entity
    @Table(name = "applications")
    class Application {
        @Id
        @NotNull
        @GeneratedValue
        Long sNo
        // Rest of the fields
    }
    @Entity
    @Table(name = "user_activity")
    class UserActivity {
        @Id
        @NotNull
        @GeneratedValue
        Long sNo
        // Rest of the fields
    }

Below Changes Need to be done in application.yml file以下更改需要在 application.yml 文件中完成

properties:
      hibernate:
        id:
          new_generator_mappings: false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 Spring 引导应用程序实体 ID 不会自动生成 - Why Spring Boot app entity id doesn't auto generate Spring MongoRepository中的自动增量_Id - Auto Increment _Id in Spring MongoRepository DB2 自动增量主键列不适用于 Spring Boot 中的 JPA 实体 - DB2 Auto increment primary key column not working with JPA entity in Spring Boot Java中数据存储区的自动增量实体ID - Auto increment entity id for datastore in java Spring Boot 不会增加 long 类型的自动生成的 id - Spring Boot doesn't increment auto-generated id with type long 如何使用 uniqe 产品代码自动增加数据库 ID,然后在 spring 启动时更改 mont 时将其重置为 1? - How to auto-increment database id with uniqe product code and then reset it to 1 when change mont in spring boot? Spring Boot 实体中自动生成的唯一键 - Unique key auto generated in Spring Boot Entity 自动递增归档不返回值(非主键) - Spring启动JPA - Auto Increment filed not returning value (Not Primary Key) - Spring boot JPA 如何使用自动增量ID在JPA中的实体中设置另一个变量 - How to use auto increment ID to set another variable in the entity in JPA Liquibase + Postgresql + Spring Jpa:Id 自动递增问题 - Liquibase + Postgresql + Spring Jpa : Id auto increment issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM