java - 如何在 postgres 中没有时区的情况下节省时间。我正在使用 hibernate Spring MVC

标签 java spring postgresql hibernate postgresql-9.1

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

关于java - 如何在 postgres 中没有时区的情况下节省时间。我正在使用 hibernate Spring MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42296669/

相关文章:

java - 嵌入式 jetty 应用程序无法从 jar 运行

java - 如果我手动构建并部署到 Tomcat,但在 IntelliJ 下无法运行 Web 应用程序?

java - Spring 的不同范围

Java - 从 .wav 中删除 header

java - 使用 jsoup 或 regex 提取 header 标签之间的 html 标签

java - spring security 4.0.0 java配置没有xml

java - 如何在 spring Controller 中使用 enum 作为参数,使用 "spring"语言扩展 swagger-codegen 生成的接口(interface)

PostgreSQL 中的 SQL MIN(value) 匹配行

ruby-on-rails - 使用 PostgreSQL 运行 rails db 迁移的最低权限

postgresql WAL 文件内部结构