Answer the question
In order to leave comments, you need to log in
CRUD Hibernate how to do sequential increment with update?
Guys, hello. I am making a simple educational app. Such a problem, when deleting a column, the id of the new record starts with the deleted id, and not with the previous one. How to make it so that it counts from the previous one, not taking into account the deleted record. And if it is possible so that when deleting, for example, 9 records, 10 records become 9, i.e. to always have a sequence, it would be great. Give plz a direction where to dig. The real code is in the screenshots, now when the application is restarted, as it should work, the recording starts from the previous one, it does not work without restarting.
Answer the question
In order to leave comments, you need to log in
First, it is not particularly clear why this is needed at all.
This is not about hibernate, but about the database you are using.
The primary key must be unique , in the case of autoincrement, also sequential (monotonically strictly increasing).
Offhand, you can do this: hang up a trigger for deletion and move row IDs, update the sequence after. However, this is a very heavy operation - imagine that the user has deleted the first line, and you have a million of them, you will have to change the IDs of a million entries.
Moreover, if you use this id somewhere in the link (for example, /movies/123) (and this is a common scenario), then when deleting all such links will become invalid.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question