Hibernate 6, id generator table strategy start value issue

Tried the following test case in hibernate 6.2.2:
Created entity with the following setup for id

@GeneratedValue(generator= "entityD", strategy = GenerationType.TABLE)
    @TableGenerator(name = "entityD", table="my_seq",pkColumnName = "my_seq_name", valueColumnName = "my_seq_val")

after that update generator for corresponding entity to 50 in the my_seq table via sql.
and ask hibernate to insert new entity.
The id will be assigned is 2, while I would expect 51…(or 52, or >50 I don’t care)
if I update generator to 100, the assigned id will be 52…

Seems a bug? In prev versions(3-5) it was working as expected.

Looking briefly in the code I see hibernate reads value from the table, updates with increment and then returns the value that was read, and after that applies formula value read - (increment size-1).
Seems logic should either return value after update or don’t substract increment size, which is 50 by default…

Test that demonstrates issue


See the migration guide about what to do here: hibernate-orm/migration-guide.adoc at 6.0 · hibernate/hibernate-orm · GitHub
You have to update the sequence to a multiple of allocationSize + 1, as that is what Hibernate does internally.