I am using spring boot with hibernate to build our application. for transaction management i am using @transaction on serviceImpl class it work properly. Transaction data rollback properly but GenerationType.IDENTITY or strategy=GenerationType.SEQUENCE value not roll back. For example if last insert row in table is 10 and lets assume next insert row value is 11 and this time because of some issue transaction is rollback after. but if we insert again it take next row value is 12 not 11. why this happens why next column value is not 11. Is there any way to take previous value.
Asked
Active
Viewed 1,665 times
1 Answers
5
Generated IDs are usually incremented outside the transaction, otherwise you would block all other transaction that need to insert new rows. The mechanism just needs to make sure that IDs are unique over all transactions.

Thomas Stets
- 3,015
- 4
- 17
- 29
-
thank you for replay you are right can you suggest me how to manage sequence of insert row if any rollback happen this not affected on my sequence. – Saurabh Verma Mar 22 '19 at 08:18
-
1gotted answer In all lock modes (0, 1, and 2), if a transaction that generated auto-increment values rolls back, those auto-increment values are “lost.” Once a value is generated for an auto-increment column, it cannot be rolled back, whether or not the “INSERT-like” statement is completed, and whether or not the containing transaction is rolled back. Such lost values are not reused. Thus, there may be gaps in the values stored in an AUTO_INCREMENT column of a table. – Saurabh Verma Mar 23 '19 at 03:50