简体   繁体   中英

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;
}

If you want to use LocalTime then you could use a Converter:

@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
    }
}

Then in your entity you would use:

@Column(name = "receipt_time")
@Convert(converter = MyConverter.class)
public LocalTime getReceiptTime() {
 return receiptTime;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM