gpt4 book ai didi

java - spring boot Hibernate报错java.lang.NoSuchMethodError : javax. persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:16 25 4
gpt4 key购买 nike


我正在使用 Spring Boot 在具有许多 Hibernate 依赖项的现有项目上做一个原型(prototype)。我正在尝试定义一个自定义的 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

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

谢谢,
水稻

最佳答案

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

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

关于java - spring boot Hibernate报错java.lang.NoSuchMethodError : javax. persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27373725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com