In 4.3, if an exception occurs in the constructor of {{SessionFactoryImpl}} (e.g. schema validation fails), the {{SessionFactoryImpl}} object is kept in memory because it was added to the {{SessionFactoryRegistry}}. In our unit tests, this causes dozens of SessionFactories to be kept in the registry, until the heap is filled and OutOfMemoryErrors are thrown.
This issue probably doesn't occur in Hibernate 5.0 because the code for adding the {{SessionFactoryImpl}} to the {{SessionFactoryRegistry}} was moved to the end of the {{SessionFactoryImpl}} constructor in HHH-9655 ([this commit|https://github.com/hibernate/hibernate-orm/commit/b318d21cc8939bd55a1c608b2cca6e109261edb9]).
I would like to propose backporting the 3 commits for HHH-9655 to the 4.3 branch. I can provide have provided a pull request. |
|