H2 database doesn't autoincrement IDs after them being set to null, while PostgreSQL does

83 Views Asked by At

My project uses PostgreSQL for production and H2 database for tests. Some content is saved to database and afterwards it is retrieved, changed and saved again to new rows. In this method some of retrieved contents' IDs are set to null, and PostgreSQL autoincrements them again when contents are being saved for the second time. In my test case H2 database doesn't do the same - it autoincrements IDs when contents are being saved for the first time, but when I retrieve them and set the IDs to null and save them again, IDs stay null. They don't get autoincremented when being saved, and only when I try to map this new object to a DTO, I get this error: identifier of an instance of X was altered from 1 to null. The method is called from a controller that I'm mocking in a test, if that makes a difference.

0

There are 0 best solutions below