One option is to visit the data again after completing each integration test. Spring offers such a function through the SqlScriptsTestExecutionListener and @Sql annotation. I know that you mentioned EAR and JBoss , so if Spring not used, I suggest that Arquillian can offer something similar.
In the case of re-sowing, the database becomes an expensive operation due to the amount of data used to test integration, another option is to use a Docker image from the database and already sown data. You will need to start the DB with data container DB with data before each integration test is completed and stopped after it is completed, in other words, you will need to manage the container life cycle throughout the integration testing. I wrote about how to do this a few months ago: Testing integration using Spring Boot, Postgres and Docker , again using Spring Boot , but ideas would be useful for use with a different structure. It covers creating Docker images with imported data, generating JPA entities from an existing schema, adding support for integration tests to start / stop a container before and after each test, and it could be easily expanded to start more than one container per test or run them at the same time, since the Docker container maps to an arbitrary host port.
At this point, it is a compromise, starting each test from a state of knowledge (IMHO, the right approach) by either re-sifting the data, or starting / stopping the containers for each individual test, or by running tests in a specific order and simply re-sowing the data before performing a set of tests.
source share