Spring引导Hibernate错误java.lang.NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()Ljavax / persistence / ForeignKey;

时间:2014-12-09 07:42:43

标签: java gradle hibernate-4.x jpa-2.1


   我正在使用Spring Boot在具有许多Hibernate依赖项的现有项目上做原型。我正在尝试定义一个自定义的LocalEntityManagerFactoryBean,我在这里得到了这个错误:

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

我已经尝试更新我的hibernate版本(由于项目向后兼容导致许多其他编译错误,无法使用所有最新版本)但是使用以下hibernate依赖图可以使其编译但仍然会得到此运行时依赖性错误。当我搜索这个错误时,所有结果都指向Hibernate 4和JPA 2.1的升级。我们已经在使用Hibernate 4+,所以只是将版本更高一点但没有运气。 Gradle的以下依赖图显示我没有任何旧版本的" 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

任何指针都会有很大帮助。

谢谢,
稻谷

1 个答案:

答案 0 :(得分:1)

尝试排除您不需要的依赖项,并为您想要的版本强制执行。 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"
        }
}