In our application we have an issue using the manytomany link. In order to easily reproduce the issue this project was created.
I attached to this bug a maven project to reproduce easily the issue.
To reproduce the issue just run the main class ockham.manytomany.Runner.
This class calls a service that create one parent entity (Workspace) and create 5000 children entities (Item).
Each Item entity is added to the worskpace entity. The item entities are create and attached one by one. At the end of each iteration, we flush and clear the
entitymanager. We do this because, in our project we have to do it due to other Hibernate executions.
If you run this main class, the process will terminate with a Java Heap space even using a -Xmx1024m parameter.
For each iteration, hibernate create a lot of Item entity and never release the heap memory. We don't understand why hibernate create as much Item and workspace instead of reuse instances.
The hibernate version used is the 5.3.7.Final but I tested also with the 5.4.23.Final.
Can you confirm that is well an issue ?
Open jdk 11, hibernate version 5.3.7, on Windows 10 OS.