首页 > 解决方案 > joda-time、jadira 和休眠

问题描述

我正在将一个 spring-boot 项目迁移到 2.5 版本,这个项目正在使用 jadira 和 joda-time。

我试图弄清楚这些库的最新版本是否与 spring-boot 所需的 hibernate 5.4 兼容。

谢谢

<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.core</artifactId>
    <version>6.0.1.GA</version>
</dependency>
<dependency>
   <groupId>joda-time</groupId>
   <artifactId>joda-time</artifactId>
   <version>2.7</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

标签: spring-boothibernate

解决方案


修复了实现 TypeContributor


public class JadiraTypesContributor implements TypeContributor
{
   private static final UserType[] userTypes = new UserType[]{
            new PersistentDateTime(),
            new PersistentDurationAsString(),
            new PersistentInstantAsMillisLong(),
            new PersistentLocalDate(),
            new PersistentLocalDateTime(),
            new PersistentLocalTime(),
            new PersistentMonthDayAsString(),
            new PersistentPeriodAsString(),
            new PersistentYears(),
            new PersistentMinutes(),
    };
    private static final CompositeUserType[]
            compositeUserTypes = new CompositeUserType[]{
            new PersistentDateMidnight(),
            new PersistentInterval(),
    };
    @Override
    public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
        for (UserType userType : userTypes) {
            typeContributions.contributeType(userType, userType.returnedClass().getName());
        }
        for (CompositeUserType compositeUserType : compositeUserTypes) {

            typeContributions.contributeType(compositeUserType, compositeUserType.returnedClass().getName());
        }
    }
}



  • 将类型贡献者添加到此文件

META-INF/services/org.hibernate.boot.model.TypeContributor


推荐阅读