Tests of fact integration with violation of restrictions due to existing records resemble a situation that I once encountered with functional tests (selenium), performed in an unpredictable order, some of them do not clean the database properly. Of course, the situation with functional tests is different, since it is more difficult to restore the state of a database (a test test cannot cancel a transaction in another jvm).
Although integration tests usually roll back transactions, you can still break this behavior if your code controls the transactions (commits) explicitly.
First, I would try to force an order, as Jarred pointed out in 3). Assuming you can then reproduce the behavior, I would then check for transactional behavior. Setting the org.hibernate.transaction logging level for debugging should show where transaction boundaries are located.
Sorry, you do not yet have a good explanation why the destruction of unit tests helps to get rid of the symptoms, in addition to the general "possible problems with metaclassification." :)
source share