I\'m using Spring Framework 3.1 with Hibernate 4.1 as a JPA provider, and I have a fully functional setup, but every time the web app is started I see this warning message:<
How are you initializing your Spring Application Context? Are you using Spring MVC?
I've seen sometimes Spring MVC XML configurations importing the other app. context XML, causing instancing twice some beans because they are declared in the application context and the web application context.
I came across the same issue but in a different scenario. The EntityManagerFactoryRegistry
produces the same HHH000436
warning, when executing multiple tests in the same run (i.e. the same JVM) started from my IDE.
The problem can surface in case there are at least two test classes using the SpringJUnit4ClassRunner
to load different Spring test application contexts each containing an EntityManagerFactory
.
The root cause is that Hibernate maintains a static registry of EntityManagerFactory
instances, where the creation of the second instance may cause the collision the log message is about. So why isn't the first instance deregistered after the first test finished executing? It normally would when the app context containing that EntityManagerFactory
instance gets destroyed. The reason it doesn't happen during test execution is that the Spring test context framework caches all loaded contexts in order to avoid re-loading the exact same context potentially needed by multiple tests. As a result, beans in these contexts doesn't get destroyed until after the last test finished executing, and Hibernate will just collect all the EntityManagerFactory
instances ever created.
It's really a non-issue, but if someone is really annoyed by the warning message, there are a few possible ways to avoid seeing it:
EntityManagerFactory
instances get a different name (they are keyed by name in the registry). Chek the constructor of EntityManagerFactoryImpl
on how the name is derived.@DirtiesContext
on the test class to cause the SpringJUnit4ClassRunner
to close the context and remove it from its context cache immediately after executing the test class.EntityManagerFactoryRegistry
to error...Hope this helps someone.