Class Loading Leak with Hibernate/Spring

202 views Asked by At

We have Spring/Hibernate-Tests which currently produce a class-loading leak. For technical reasons, the springcontext is initiated per test method. With the initialization of the spring context, a hibernate session is also initizlized.

We could observe that the number of loaded classes is increasing steadily. Upon inspection with JProfiler, we found out, that any instantiation of the hibernate session triggers a load on all entity-class objects. As we have three digit number of hibernate entities, this leads to a massive bloat in metaspace and compressed class space.

The question is: Why is the same class loader loading the same classes again and again and does not realize, that the class-objects are already loaded?

Edit: Clarification of the scenario

This issue occured as part of a software modernization-project, where functions from a legacy app are ported into a spring managed part of the application. During production this works fine - the applicationserver initializes the spring context (and therefore hibernate), the legacy core accesses this via some static acessors.

In testing stage we have to integrate the legacy testing framework with the spring core. For technical reasons (the old testing framework is somewhat quirky) we have to re-establish the spring-context per test, not per test class. As there is quite a number of tests in the testset, this eventually leads to a OOME within the compressed class space.

As the tests actually make use of the database connection, each test initializes a hibernate session. We are using Spring 5.2.13 and Hibernate 5.4.29.

0

There are 0 answers