如何在postgres中节省没有时区的时间。我使用休眠Spring MVC的
问题描述:
ERROR: column "receipt_time" is of type time without time zone but expression is of type bytea Hint: You will need to rewrite or cast the expression. Position: 490如何在postgres中节省没有时区的时间。我使用休眠Spring MVC的
private LocalTime receiptTime;
@Column(name = "receipt_time")
public LocalTime getReceiptTime() {
return receiptTime;
}
public void setReceiptTime(LocalTime receiptTime) {
this.receiptTime = receiptTime;
}
答
如果你想使用本地时间,那么你可以使用一个转换器:
@Converter
public class MyConverter implements AttributeConverter<LocalTime, Time> {
@Override
public Time convertToDatabaseColumn(LocalTime localTime) {
if(localTime == null){
return null;
}
// convert LocalTime to java.sql.Time
}
@Override
public LocalTime convertToEntityAttribute(Time time) {
if(time == null){
return null;
}
// convert java.sql.Time to LocalTime
}
}
然后在你的实体,需要使用:
@Column(name = "receipt_time")
@Convert(converter = MyConverter.class)
public LocalTime getReceiptTime() {
return receiptTime;
}
也未尝要考虑的是更新Hibernate,所以他们开箱即用。 – Kayaman