Java hibernate core&;hibernate注释-冲突
我得到一个错误:Java hibernate core&;hibernate注释-冲突,java,hibernate,hibernate-annotations,verifyerror,Java,Hibernate,Hibernate Annotations,Verifyerror,我得到一个错误: 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.GenericEnumUse
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核心
这样的依赖项时,它还会自动将其依赖项导入到项目中,其中一个是hibernate注释
库。结果是两个不同版本的库,这是Maven中的一个常见问题,它们提供了一种很好的方法来查找这些依赖项从何处导入
在这种情况下,只需从项目中删除hibernate注释
依赖项,让hibernate核心
为您导入即可。
您如何找到这个重复库冲突?一个好方法是使用Maven提供给我们的依赖树插件:mvn dependency:tree-Dverbose-Dincludes=org.hibernate.
。这将显示项目中org.hibernate的组或子组中的所有库依赖项。也可以考虑通过将<代码> > FielOutPoToNo.txt>代码>输出到文件,这样就更容易查看,特别是如果您使用Windows命令行。
以下是我拥有的一个hibernate项目的示例输出:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
正如您所看到的,hibernate核心
自动导入hibernate公共注释
。如果该版本与pom中包含的版本不同,Maven将同时包含这两个版本,从而导致问题。最好是让核心导入完成它的工作,除非您有很好的理由更改注释版本
如果确实要从核心库中删除依赖项,可以通过添加
标记来实现。但是请注意,由于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>
org.hibernate
冬眠核心
4.0.1.最终版本
org.hibernate.common
hibernate commons注释
我认为hibernate核心默认包含注释依赖项。因此,在使用maven时包含注释将导致项目中有2个注释包。您可以从hibernate core中排除annotations包,或者从项目中删除annotations依赖项。
<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>