gpt4 book ai didi

java - hibernate-core 和 hibernate-annotation - 冲突

转载 作者:行者123 更新时间:2023-12-03 01:49:36 28 4
gpt4 key购买 nike

我收到错误:

java.lang.VerifyError: (class: org/hibernate/type/BasicTypeRegistry, method:  signature: ()V) Incompatible argument to function     
at org.hibernate.type.TypeResolver.(TypeResolver.java:59)
at com.gs.ctt.cb.types.usertypes.GenericEnumUserType.setParameterValues(GenericEnumUserType.java:46)
at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:339)



由于可能的原因是库冲突,我发现该类:org.hibernate.cfg.AnnotationConfiguration在以下两个中都可用:

  • hibernate-annotations-3.3.0
  • hibernate-core-3.6.4

我需要完全摆脱 hibernate 注释吗?为什么?

最佳答案

Maven 中的许多依赖项也依赖于其他库来运行。当包含像 hibernate-core 这样的依赖项时它还会自动将其依赖项导入到您的项目中,其中之一是 hibernate-annotations图书馆。结果是 2 个具有不同版本的库,这是 Maven 中的常见问题,它们提供了一种很好的方法来查找这些依赖项从何处导入。

在这种情况下,只需删除 hibernate-annotations来自您的项目的依赖项并让 hibernate-core为您导入。

您自己如何找到这个重复的库冲突?一个很好的方法是使用 Maven 提供给我们的依赖树插件:mvn dependency:tree -Dverbose -Dincludes=org.hibernate.* 。这将显示项目中 org.hibernate 组或子组中的所有库依赖项。 还可以考虑通过附加 > fileOutputName.txt 输出到文件以便更容易查看,特别是如果您使用 Windows 命令行。

这是我拥有的具有 hibernate 功能的项目的示例输出:

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>

还有mvn dependency:tree调用:

[INFO] +- org.hibernate:hibernate-core:jar:4.0.1.Final:compile
[INFO] | +- (org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile - omitted for duplicate)
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] +- org.hibernate.common:hibernate-commons-annotations:jar:tests:4.0.1.Final:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] \- org.hibernate:hibernate-entitymanager:jar:4.0.1.Final:compile
[INFO] +- (org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile - omitted for duplicate)
[INFO] \- (org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile - omitted for duplicate)

如您所见 hibernate-core自动导入hibernate-commons-annotations 。如果该版本与您在 pom 中包含的版本不同,Maven 将同时包含这两个版本,从而导致问题。最好让核心导入去做它的事情,除非您有充分的理由更改注释版本。

<小时/>

如果您确实想从核心库中删除依赖项,可以通过添加 <exclusions> 来实现。标签。但要小心,因为 hibernate 套件的其他部分会尝试导入注释包,因此您最终可能会从大量依赖项中排除注释。

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
<exclusions>
<exclusion> <!-- remove annotations inclusion -->
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>

关于java - hibernate-core 和 hibernate-annotation - 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27848337/

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