如何在 postgres 中节省没有时区的时间。我正在使用休眠 Spring MVC
how to save time without time zone in postgres . i am using hibernate 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
private LocalTime receiptTime;
@Column(name = "receipt_time")
public LocalTime getReceiptTime() {
return receiptTime;
}
public void setReceiptTime(LocalTime receiptTime) {
this.receiptTime = receiptTime;
}
如果您想使用 LocalTime,那么您可以使用转换器:
@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;
}
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
private LocalTime receiptTime;
@Column(name = "receipt_time")
public LocalTime getReceiptTime() {
return receiptTime;
}
public void setReceiptTime(LocalTime receiptTime) {
this.receiptTime = receiptTime;
}
如果您想使用 LocalTime,那么您可以使用转换器:
@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;
}