Issue
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
After running spring boot application a domain hibernate_sequence is automatically created in database which contains
+----------+
| 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.
+----------+
| next_val |
+----------+
| 3893 |
| 3893 |
| 3893 |
+----------+
Now suppose i want to save one row in application table then serial number is now starting from 3894.
How i manage or control this auto increment serial number in my multiple spring boot entity?
@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
}
Solution
Below Changes Need to be done in application.yml file
properties:
hibernate:
id:
new_generator_mappings: false
Answered By - chaitanya gupta
Answer Checked By - Marilyn (JavaFixing Volunteer)