Spring boot Hibernate error java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

我的未来我决定 提交于 2019-12-07 19:44:31

问题



I am doing a prototype using Spring Boot on an existing project with many Hibernate dependencies. I am trying to define a custom LocalEntityManagerFactoryBean and it is here that I get this error:

java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

I have tried updating my hibernate versions (could not use all latest versions due to project backward compatibility causing many other compile errors) but with the following hibernate dependency graph could get it to compile but still get this runtime dependency error. When I searched for this error all results to pointed to upgrade of Hibernate 4 and JPA 2.1. 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 do not have any 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 will be of much help.

Thanks,
Paddy


回答1:


Try excluding dependencies that you don't need and enforcing versions for those you want. E.g.:

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"
        }
}


来源:https://stackoverflow.com/questions/27373725/spring-boot-hibernate-error-java-lang-nosuchmethoderror-javax-persistence-joinc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!