首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring错误地更新postgres中的时间戳wo时区

Spring错误地更新postgres中的时间戳wo时区
EN

Stack Overflow用户
提问于 2018-06-08 14:25:23
回答 1查看 719关注 0票数 2

我一直试图使用更新stmt更新时间戳字段。我尝试了java.sql.timestamp、java.util.date、Calendar、LocalDateTime、ZonedDateTime和其他一些java date util包。他们似乎都不起作用。

列: commit_ts (在Postgresql中没有Timezone的TimeStamp)在JPA/Hibernate中定义为

代码语言:javascript
复制
@Column(name = "COMMIT_TS")
@Temporal(TemporalType.TIMESTAMP)
private Timestamp commitTs;

以下是查询

代码语言:javascript
复制
@Timed(name = "updateWorkAllocationStatus")
@Transactional
@Modifying(clearAutomatically = true)
@Query(
      nativeQuery = true,
      value = "UPDATE wlm_work_allocation SET commit_ts=:ts " + 
              "WHERE allocation_id = :allocationId " + 
              "and status = :status " + 
              "and commit_ts == null"
)
int updateWorkAllocationStatus(
    @Param("timestamp") Timestamp ts,
    @Param("allocationId")Long allocationId,
    @Param("status")String status
);

我也试过NativeQueries

代码语言:javascript
复制
@NamedNativeQuery(name = "WorkAllocationEntity.updateCommitTs",
        query="UPDATE wlm_work_allocation SET commit_ts= TIMESTAMP WHERE allocation_id=:allocationId and status=:status and commit_ts==null")

注意:根据这个链接,SQL标准要求只写时间戳就等于没有时区的时间戳,PostgreSQL尊重这种行为。https://www.postgresql.org/docs/9.1/static/datatype-datetime.html

Springboot版本:1.5.7 version

Postgres JDBC驱动程序: 9.0-801.jdbc4

PostgresSQL DB: 9.6.5

代码语言:javascript
复制
Error: 
org.postgresql.util.PSQLException: ERROR: operator does not 
exist: timestamp without time zone == unknown
Hint: No operator matches the given name and argument type(s). 
You might need to add explicit type casts.

有人能帮忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-08 14:30:04

JPQL和SQL中的比较运算符是=非==

代码语言:javascript
复制
commit_ts==null 

应该是

代码语言:javascript
复制
commit_ts is null
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50762781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档