多个 spring 引导实体上的自动递增 ID
Auto Increment Id on multiple spring boot entity
我的 spring 启动应用程序中有 3 个 class,在所有这 3 个 class 中,我使用的是可用的 sNo(序列号),它是它的主键table
在 运行 spring 启动应用程序后,一个域 hibernate_sequence 会自动在数据库中创建
其中包含
+----------+
| next_val |
+----------+
| 1 |
| 1 |
| 1 |
+----------+
现在我使用一个端点将一些用户保存在我的数据库中。
例如,我在我的用户 table 中保存了 3892 行(记录),之后我的 hibernate_sequence 包含了。
+----------+
| next_val |
+----------+
| 3893 |
| 3893 |
| 3893 |
+----------+
现在假设我想在应用程序中保存一行 table 那么序列号现在从 3894 开始。
我如何管理或控制我的多个 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
}
以下更改需要在 application.yml 文件中完成
properties:
hibernate:
id:
new_generator_mappings: false
我的 spring 启动应用程序中有 3 个 class,在所有这 3 个 class 中,我使用的是可用的 sNo(序列号),它是它的主键table
在 运行 spring 启动应用程序后,一个域 hibernate_sequence 会自动在数据库中创建 其中包含
+----------+
| next_val |
+----------+
| 1 |
| 1 |
| 1 |
+----------+
现在我使用一个端点将一些用户保存在我的数据库中。 例如,我在我的用户 table 中保存了 3892 行(记录),之后我的 hibernate_sequence 包含了。
+----------+
| next_val |
+----------+
| 3893 |
| 3893 |
| 3893 |
+----------+
现在假设我想在应用程序中保存一行 table 那么序列号现在从 3894 开始。
我如何管理或控制我的多个 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
}
以下更改需要在 application.yml 文件中完成
properties:
hibernate:
id:
new_generator_mappings: false