Possible Memory Leak on JavaTypeDescriptorRegistry


When using hibernate with a Container Managed EntityManagerFactory
some classes are loaded outside application classloader.

Every time that a application starts hibernate register JavaTypeDescriptos on JavaTypeDescriptorRegistry.INSTANCE.

The problem is that anybody clean it on application stop, and it is a static instance inside hibernate module classloader.

Possible solution: work with a weak reference of class.


Wildfly 8.2.0.Final
Jdk 1.8.0_25
Hibernate 4.3.6 (wildfly)


Anthony Vanelverdinghe
November 10, 2016, 12:29 PM

Thanks for the help .

would a pull request for this (using WeakReference to avoid the memory leak) require additional unit tests in order to be accepted?

Steve Ebersole
November 10, 2016, 2:42 PM

The problem with the WeakReference solution is what hints at - namely when those references go away there is nothing in those Maps anymore for other SessionFactories on the same ClassLoader. This is why the change in 6.0 is really the more appropriate change. But regarding the WeakReference, I am not sure of the type of testing we would do anyway.

Dyorgio Nascimento
November 10, 2016, 4:27 PM

I know that the hibernate project have its own priorities, but Wildfly 8, 9 and 10 will be on the market for long years, most people only are using 8 and 9, looking for stability.
I agree with you, 6.0 have the more appropriate solution, but many applications will continue to use 4 and 5 versions for many years.

Steve Ebersole
November 10, 2016, 4:49 PM

FWIW we define WF modules for all new Hibernate releases (starting in 5.2) - https://repo1.maven.org/maven2/org/hibernate/hibernate-orm-modules/ and you could certainly define yoru own.

I certainly respect people's decision to stick with older versions of things, but they also have to respect the decision of projects to not back port fix to all version back to 1.0

Steve Ebersole
November 14, 2016, 5:32 PM

what do you think of a 5.3 release that ports the changes from 6.0 work necessary to scope these registries and avoid this bug? Or do we just expect people to live with this until 6.0?




Dyorgio Nascimento

Fix versions




Suitable for new contributors


Requires Release Note


Pull Request




Affects versions