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

Spring boot Hibernate错误java.lang.NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/foreignKey;,java,gradle,hibernate-4.x,jpa-2.1,Java,Gradle,Hibernate 4.x,Jpa 2.1,我正在使用SpringBoot在一个具有许多Hibernate依赖项的现有项目上做一个原型。我试图定义一个自定义LocalEntityManagerFactoryBean,在这里我得到了以下错误: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey; 我曾尝试更新我的hibernate版本(由于项目向后兼容性导致许多其他编译错误,因此无法使用所有最


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

java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
我曾尝试更新我的hibernate版本(由于项目向后兼容性导致许多其他编译错误,因此无法使用所有最新版本),但使用以下hibernate依赖关系图可以使其编译,但仍然会出现此运行时依赖关系错误。当我搜索这个错误时,所有的结果都指向Hibernate4和JPA2.1的升级。我们已经在使用Hibernate4+,所以只是把版本改高了一点,但运气不好。Gradle的以下依赖关系图显示,我没有任何旧版本的“org.hibernate.javax.persistence:hibernate-jpa-2.0-api”

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

谢谢,

Paddy

尝试排除您不需要的依赖项,并强制执行您想要的版本。例如:

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

不同hibernate版本之间存在版本冲突。请确保您的war文件中有hibernate 4.3.x。您好@Jens,是的,我将尝试删除所有其他版本,但仍存在一些依赖项,如hibernate common Annotation或类似的依赖项,它们仍处于3.5.6版本,更糟的是,由于某些原因,尚未升级到使用hibernate-jpa-api-2.1。你是说我应该只有4.3.x的内核,entitymanager等等。?只是想了解一下Hibernate方面或JPA方面的问题(我认为Hibernate我现有的Hibernate 4.1.2核心库依赖关系是指一个仅在JPA 2.1中可用的类,所以如果我升级api依赖关系版本,它应该可以工作,不是吗)?还有@Jens,你知道是否有一种方法可以单独排除依赖项的特定版本吗?对于注释,请尝试使用
org.hibernate.common:hibernate commons annotations:4.0.5.Final
Oops对不起,错了,显然还有一个hibernate注释仍然在3.5.6。有关于按版本进行全局排除的想法吗?谢谢@Kranach,我不需要强制包含任何内容,只是删除了“hibernate注释”帮助我克服了这个问题。显然,hibernate核心的更新版本似乎包含了hibernate注释库中的任何内容。
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"
        }
}