You can run single tests or groups of applicable groups as a single transaction, and then roll back at the end. (This can be tricky if the tests themselves contain multiple transactions, and your db does not support nested transactions or savepoints.)
Alternatively, create a test database created by scripts. DbUnit can help here, like other database generators like LiquiBase , dbmaintain , dbmigrate. Then you can delete the entire database and recreate for each test or test group. The usefulness of this approach decreases as the set of test data becomes large and overhead increases.
The final option is to ensure that your tests are not dependent on the generated identifier, since fragile tests will be created depending on the generated value. It is useful to test the generated identifier, so check these values ββfor some tests, but I'm not sure if there is any value when testing identifiers for all tests.
EDIT: OP asked to use sleep mode to recreate the circuit. This can be organized by creating a new SessionFactory for each test and setting "hibernate.hbm2dd.auto" to "true" when creating the SessionFactory. I mention the drop-create drop-efficiency - this also applies to this case.
source share