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