Reputation: 2761
Background: WAR application utilizing Spring + Hibernate in "Native Hibernate use" scenario (https://docs.jboss.org/author/display/WFLY/JPA+Reference+Guide#JPAReferenceGuide-NativeHibernateuse)
Everything works as expected while using Hibernate version bundled with WFLY 11 (i.e. 5.1.10.Final) with the following configuration in jboss-deployment-structure.xml
for org.hibernate
module:
<jboss-deployment-structure>
<deployment>
<dependencies>
...
<module name="org.hibernate"/>
...
</dependencies>
<exclude-subsystems>
<subsystem name="jaxrs" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Problem occurs while upgrading to Hibernate 5.2.16.Final according to this guide. As far as I understand, after unpacking hibernate-orm-modules-5.2.16.Final-wildfly-11-dist.zip
in the modules directory I should be able to define the Hibernate module with slot 5.2 or 5.2.16.Final, i.e.:
<jboss-deployment-structure>
<deployment>
<dependencies>
...
<module name="org.hibernate" slot="5.2"/>
...
</dependencies>
<exclude-subsystems>
<subsystem name="jaxrs" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
but the above config results in
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.hibernate.SessionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1507)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721)
... 32 more
While changing <module name="org.hibernate" slot="5.2"/>
to e.g. <module name="org.hibernate" slot="5.23456789"/>
Wildfly raises exception that such module version does not exist so I assume that modules are loaded correctly.
Is there something I missed in this configuration? Adding persistence.xml
with <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/>
doesn't work for this scenario as I don't use persistence units managed by Wildfly and injected with @PersistenceContext
annotation.
Upvotes: 0
Views: 2118
Reputation: 2761
I finally found a workaround for my problem.
I tried to convert "Native Hibernate use" pattern to Wildfly-managed entity manager (which means introducing persistence.xml and Spring LocalContainerEntityManagerFactoryBean responsible for parsing persistence.xml). This introduced another sort of exceptions which were rather app- or configuration-specific and are irrelevant in this case.
What really helped was logging jars loaded by WFLY classloaders ($JAVA_OPTS += '-verbose:class'
). It turned out that regardless of specifying slots (<module name="org.hibernate" slot="5.2"/>
- or in case of persistence.xml: <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/>
), WFLY always loaded some core classes (SessionFactory for example) from the main slot which caused linkage exceptions in the best case or 'silent' errors in the worst case.
What helped was replacing the main hibernate module.xml (${jboss.home.dir}/modules/system/layers/base/org/hibernate/main/module.xml
) with the same content as ${jboss.home.dir}/modules/system/layers/base/org/hibernate/5.2/module.xml
which means that now my ${jboss.home.dir}/modules/system/layers/base/org/hibernate/main/module.xml
looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<module-alias xmlns="urn:jboss:module:1.3"
name="org.hibernate" slot="main"
target-name="org.hibernate" target-slot="5.2.16.Final"
/>
This way Wildfly loads correct vesrions of Hibernate jars regardless of the 'main' or '5.2' slot as both point to the same Hibernate version.
The solution works for persistence.xml pattern as well as for the "Native Hibernate use" pattern.
Upvotes: 1