16:57:41,389 ERROR [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 86) Application startup failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
I am deploying a .war file in JBoss EAP 6.4
I am using Spring Boot version '1.2.4.RELEASE'
I have tried:
Creating a jboss-deployment-structure.xml with:
<jboss-deployment-structure> <deployment> <exclude-subsystems> <subsystem name="jpa" /> </exclude-subsystems> <exclusions> <module name="javax.persistence.api" /> <module name="org.hibernate"/> </exclusions> </deployment> </jboss-deployment-structure>
Note: excluding the module
javaee.api
creates more exceptionsAlso, changed standalone.xml to remove the jpa subsystem:
<subsystem xmlns="urn:jboss:domain:jpa:1.1"> <jpa default-datasource="" default-extended-persistence-inheritance="DEEP"/> </subsystem>
Also changed
/middleware/jboss64/modules/system/layers/base/javaee/api/main/module.xml
:<module name="javax.persistence.api" export="false"/>
I can see from the Spring Boot 1.2.4.RELEASE Documentation -
org.springframework.data spring-data-jpa
1.7.2.RELEASE
I can see in the
spring-data-jpa 1.7.x pom.xml
:<hibernate>3.6.10.Final</hibernate>
But the war file was generated using gradle 2.4 contains Hibernate-core-4.3.8.jar
and hibernate-jpa-2.1-1.0.0.jar
, why ?
The only theory I have is that JBoss is inserting its own Jpa jar and NOT the hibernate jar which cause mismatch of the Hibernate and jpa API causing the exception.
I think downgrading the the Hibernate version in spring boot project will fix this mismatch, so I changed build.gradle ...
configurations.all { resolutionStrategy { eachDependency { if (it.requested.group == 'org.hibernate') { it.useVersion '4.2.19.Final' } } }
I got following error
Could not resolve all dependencies for configuration ':callcentre2:compile'. Could not resolve org.hibernate:hibernate-validator:4.2.19.Final.
( ....some https url here but I cant write it here cos stackoverflow does not let me save the question)
Am I on the right track to downgrade the Hibernate version if so how do I fix the above build error? What is the repo for Hibernate?
Update:
I fixed the above by including ...
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
// Use Hibernate 4.2
if (details.requested.name == "hibernate-core") {
details.useTarget "org.hibernate:hibernate-core:4.2.19.Final"
}
if (details.requested.name == "hibernate-entitymanager") {
details.useTarget "org.hibernate:hibernate-entitymanager:4.2.19.Final"
}
// Use JPA 2.0
if (details.requested.name == "hibernate-jpa-2.1-api") {
details.useTarget "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final"
}
}
}
But now I am getting on the JBoss EAP 6.4 :
Caused by: java.lang.LinkageError: Failed to link org/springframework/boot/orm/jpa/hibernate/SpringJtaPlatform (Module "deployment.callcentre2.war:main" from Service Module Loader) at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:487) [jboss-modules.jar:1.3.6.Final-redhat-1] ... 31 more Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/jta/platform/internal/AbstractJtaPlatform at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.8.0_40] at java.lang.ClassLoader.defineClass(ClassLoader.java:760) [rt.jar:1.8.0_40] at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:361) [jboss-modules.jar:1.3.6.Final-redhat-1] at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:482) [jboss-modules.jar:1.3.6.Final-redhat-1] ... 53 more Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform from [Module "deployment.callcentre2.war:main" from Service Module Loader]