Could you elaborate on why each of your integration tests needs to create a new SessionFactory? Your tests could run much faster if that wasn’t the case, and - like you’ve seen - there’s many problems for us in caching things within a static global scope w/o polluting the classloader. Most of our users, as far as I know, either run in modular environments which would dump the classloader after a deployment is terminated, or work on the opposite spectrum: a simple single classloader, but have the application booted only once. Taking a step back, perhaps Hibernate shouldn’t store any state at all in such a static scope; unfortunately generating new class definitions within the current classloader will have this side-effect. It might not be obvious and we might log some warnings about it, but this won’t solve the problem you’re reporting. |