We have a problem where our database size grows over time more than expected. We've traced it down to the following issue:
I have some entities that are using OneToMany relationship with orphanRemoval set to true. I use a new EntityManager for each transaction (which normally happens in multithreaded application). When I create a child entity in one transaction and then remove it in another transaction, the database still contains 1 child entity. If I remove it and add another child entity, the database contains 3 child entities. If I use the same EntityManager for both transactions for these scenarios, the database contains 0 and 2 child entities respectively.
The expected result is 0 and 1 respectively, regardless of which entity manager is used.
The test case attached, I was using version 2.3.7_08.