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.
Asked
Active
Viewed 56 times
0
-
Please provide enough code so others can better understand or reproduce the problem. – Community Jun 14 '22 at 12:33
-
H2 is not Postgres. Another example of the fallacy of testing on 1 RDBMS with implementation on another. Postgres is open source and free; install and test with it. – Belayer Jun 14 '22 at 14:15
-
I'm not in a position to choose databases. I know that PostgreSQL wasn't working out well for the tests, and that's why H2 was chosen. – bluebird Jun 14 '22 at 14:49