Java 在Spring Boot中从org.joda.time.Interval迁移

Java 在Spring Boot中从org.joda.time.Interval迁移,java,hibernate,spring-boot,jodatime,java-time,Java,Hibernate,Spring Boot,Jodatime,Java Time,我曾经应用org.joda.time.Interval来表示一个具有固定开始和结束时间(不同于独立于特定时间的持续时间)的时间间隔,以通过REST进行交换,并在Spring Boot server应用程序(2.2.2.RELEASE)中存储能量计划 我尝试了不同的方法通过JPA/Hibernate存储对象的org.joda.time.Interval字段: jadira(7.0.0.CR1),在字段定义上方带有注释(@Type(Type=“org.jadira.usertype.dateand

我曾经应用
org.joda.time.Interval
来表示一个具有固定开始和结束时间(不同于独立于特定时间的持续时间)的时间间隔,以通过REST进行交换,并在Spring Boot server应用程序(2.2.2.RELEASE)中存储能量计划

我尝试了不同的方法通过JPA/Hibernate存储对象的
org.joda.time.Interval
字段:

  • jadira
    (7.0.0.CR1),在字段定义上方带有注释(
    @Type(Type=“org.jadira.usertype.dateandtime.joda.PersistentInterval”)
  • jadira
    (7.0.0.CR1),带有属性
    spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true
    set
然而,我总是得到

@OneToOne or @ManyToOne on de.iwes.enavi.cim.schedule51.Schedule_MarketDocument.matching_Time_Period_timeInterval references an unknown entity: org.joda.time.Interval
问题:

  • 有没有办法让hibernate使用
    org.joda.time.Interval
  • org.joda.time.Interval
    迁移的首选解决方案是什么,因为
    java.time
    没有类似的Interval类

  • 最后我写了一个自定义类:

    @Entity
    public class FInterval {
    
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO) 
        private long id;
    
        @Column
        private long startMillis;
    
        @Column
        private long endMillis;
    
        public FInterval() {
        }
    
        public long getStartMillis() {
            return startMillis;
        }
    
        public void setStartMillis(long start) {
            this.startMillis = start;
        }
    
        public long getEndMillis() {
            return endMillis;
        }
    
        public void setEndMillis(long end) {
            this.endMillis = end;
        }
    
        public FInterval(Interval entity) {
                this.startMillis = entity.getStartMillis();
                this.endMillis = entity.getEndMillis();
            }
    
        public Interval getInterval() {
            return new Interval(this.startMillis,this.endMillis);
        }
    }
    
    和属性转换器:

    @Converter(autoApply = true)
    public class IntervalAttributeConverter implements AttributeConverter<Interval, FInterval> {
    
        @Override
        public FInterval convertToDatabaseColumn(Interval attribute) {
            return new FInterval(attribute);
        }
    
        @Override
        public Interval convertToEntityAttribute(FInterval dbData) {
            return dbData.getInterval();
        }
    }
    
    @转换器(autoApply=true)
    公共类IntervalAttributeConverter实现AttributeConverter{
    @凌驾
    public FInterval convertToDatabaseColumn(Interval属性){
    返回新的FInterval(属性);
    }
    @凌驾
    公共间隔convertToEntityAttribute(FInterval dbData){
    返回dbData.getInterval();
    }
    }