Spring boot Hibernate error java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey () Ljavax / persistence / ForeignKey;
I am prototyping using Spring Boot on an existing project with many Hibernate dependencies. I am trying to define a custom LocalEntityManagerFactoryBean and this is where I get this error:
java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
I tried updating my hibernate versions (couldn't use all the latest versions due to project backward compatibility causing many other compilation errors) but with the following hibernate dependency graph it would be possible to compile it but still get this runtime dependency error ... When I was looking for this error, all results pointed to Hibernate 4 and JPA 2.1 update. We were already using Hibernate 4+, so just changed the version a little higher, but no luck. The following dependency graph from Gradle shows that I don't have an old version of "org.hibernate.javax.persistence: hibernate-jpa-2.0-api"
| +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
| | +--- org.hibernate:hibernate-core:4.3.7.Final
| | | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
| | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.hibernate:hibernate-validator:5.1.3.Final
| | | +--- org.hibernate:ejb3-persistence:1.0.2.GA
| | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final
| | | | | | +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
| | | | | | +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
| | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | | | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
| | +--- org.hibernate:hibernate-core:4.3.7.Final
| | | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
| | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.hibernate:hibernate-validator:5.1.3.Final
| | | +--- org.hibernate:ejb3-persistence:1.0.2.GA
| | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final
| | | | | | +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
| | | | | | +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
| | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | | | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
| | +--- org.hibernate:hibernate-core:4.3.7.Final
| | | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
| | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.hibernate:hibernate-validator:5.1.3.Final
| | | +--- org.hibernate:ejb3-persistence:1.0.2.GA
| | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final
| | | | | | +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
| | | | | | +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
| | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | | | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
| | +--- org.hibernate:hibernate-core:4.3.7.Final
| | | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
| | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.hibernate:hibernate-validator:5.1.3.Final
| | | +--- org.hibernate:ejb3-persistence:1.0.2.GA
| | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final
| | | | | | +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
| | | | | | +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
| | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | | | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| +--- org.hibernate:hibernate-entitymanager:4.3.7.Final
| | +--- org.hibernate:hibernate-core:4.3.7.Final
| | | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
| | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate.common:hibernate-commons-annotations:4.0.5.Final (*)
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| +--- org.hibernate:hibernate-validator:5.1.3.Final
| | | +--- org.hibernate:ejb3-persistence:1.0.2.GA
| | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final
| | | | | | +--- org.hibernate:hibernate-core:3.5.6-Final -> 4.3.7.Final (*)
| | | | | | +--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
| | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | | | | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | | | | | | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | | | | | | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | | | | | | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | | | | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
| | +--- org.hibernate:hibernate-core:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-entitymanager:4.2.0.Final -> 4.3.7.Final (*)
| | +--- org.hibernate:hibernate-annotations:3.5.6-Final (*)
| | +--- org.hibernate:hibernate-validator:4.2.0.Final -> 5.1.3.Final (*)
| | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
| | | | +--- net.sf.beanlib:beanlib-hibernate:5.0.3beta
Any pointers would be very helpful.
Thanks
Paddy
Try to exclude dependencies you don't need and apply versions for the ones you want. For example:.
configurations.all { conf ->
exclude group: 'org.hibernate', module: 'hibernate-annotations'
resolutionStrategy {
// Forces one verion among the project
force "org.hibernate.common:hibernate-commons-annotations:4.0.5.Final"
}
}