尝试使用Hibernate 5.2.1运行Junit测试时出错

时间:2016-08-04 11:35:58

标签: java hibernate

尝试使用Hibernate 5.2.1运行Junit测试,并发生以下错误:

java.lang.AbstractMethodError: Method org/jadira/usertype/dateandtime/joda/PersistentDateTime.nullSafeSet(Ljava/sql/PreparedStatement;Ljava/lang/Object;ILorg/hibernate/engine/spi/SharedSessionContractImplementor;)V is abstract
  at org.jadira.usertype.dateandtime.joda.PersistentDateTime.nullSafeSet(PersistentDateTime.java)
  at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:160)
  at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2646)
  at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2621)
  at org.hibernate.persister.entity.AbstractEntityPersister$4.bindValues(AbstractEntityPersister.java:2832)
  at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:41)
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2840)
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3411)

    .....

在我们的pom中,我们有下一个依赖项:

<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.spi</artifactId>
    <version>2.0.1</version>
</dependency>
<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.jodatime</artifactId>
    <version>2.0.1</version>
</dependency> 
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.8.2</version>
</dependency>

1 个答案:

答案 0 :(得分:1)

该项目不支持最新的Hibernate,并且依赖于Hibernate 5.2中已弃用的方法。

相反,您需要使用usertype.core版本6.0.0 or later,因为引入了对Hibernate 5.2的支持。

usertype.jodatime Maven工件中的类已移至usertype.core,因此您需要:

<dependency>
  <groupId>org.jadira.usertype</groupId>
  <artifactId>usertype.core</artifactId>
  <version>6.0.1.GA</version>
</dependency>