We run into a simliar error but with a (presumeably) different reason:
We dont' define allocationSize
explicitly (and therefor have the default value of 50
). We had our application running but than dropped the database and re-created it. Hibernate had his id-cache, used all of it, then communicated with the database to get new ids.
Now the hibernate-id cache was at least at 50 (might have been a lot higher for some tables), but the database dropped, rebuilt and is now empty. So there was some inconsistency already ... but for whatever reason hibernate then started the next round of ids at -48.
We run into a follow-up-error because our entities had ids defined with datatype int
instead of Integer
and when hibernate continued counting up and reached the entity with 0
it thought, that it is not in the database yet, tried to make an INSERT
instead of an UPDATE
and got a key validation error.
I still can't explain why hibernate decides to start the keys at -48
when running into this inconsistency ... but for us the error could be solved by simply shutting down the aplication before changing sequences in the database. Also all our entities now use Integer
instead of int
for ids.
Hope this information is helpful for someone out there.