我的 Spring Boot 應用程式中有 3 個類,在所有這 3 個類中,我都使用了一個可變的 sNo(序列號),它是該表的主鍵
運行 Spring Boot 應用程式后,會在資料庫中自動創建一個域 hibernate_sequence,其中包含
----------
| next_val |
----------
| 1 |
| 1 |
| 1 |
----------
現在我正在使用一個端點來保存我的資料庫中的一些用戶。例如,在我的 hibernate_sequence 包含之后,我在用戶表中保存了 3892 行(記錄)。
----------
| next_val |
----------
| 3893 |
| 3893 |
| 3893 |
----------
現在假設我想在應用程式表中保存一行,那么序列號現在從 3894 開始。
我如何在我的多個 Spring Boot 物體中管理或控制這個自動遞增序列號?
@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
}
uj5u.com熱心網友回復:
以下更改需要在 application.yml 檔案中進行
properties:
hibernate:
id:
new_generator_mappings: false
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/448515.html
