我曾经申请org.joda.time.Interval
表示具有固定开始和结束时间(不同于独立于特定时间的持续时间)的时间间隔,以通过 REST 进行交换并将能量计划存储在 Spring Boot 服务器应用程序 (2.2.2.RELEASE) 中。
我尝试了不同的方法来org.joda.time.Interval
通过 JPA/Hibernate存储对象的字段:
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
集但是,我总是得到
@OneToOne or @ManyToOne on de.iwes.enavi.cim.schedule51.Schedule_MarketDocument.matching_Time_Period_timeInterval references an unknown entity: org.joda.time.Interval
问题:
org.joda.time.Interval
?org.joda.time.Interval
由于java.time
没有类似的区间类,迁移的首选解决方案是什么?我最终编写了一个自定义类:
@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();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句