弹簧数据JPA PostgreSQL:操作员不存在:没有时区的时间戳> = bytea
使用Spring Boot 2.6.6,Spring Data JPA,Hibernate 5.6.7. -Final,PostgreSQL驱动程序42.3.3,PostgreSQL Server 14。
我有查询:
从“用户” u中选择u。
但是它不起作用。
我有错误:
org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone >= bytea
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
我打开了SQL参数的Hibernate调试,请参阅下一行:
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARBINARY] - [null]
o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARBINARY] - [null]
o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARBINARY] - [null]
o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARBINARY] - [null]
为什么 varbinary
?
我尝试了 java.util.date
, java.time.localdatetime
- 相同错误。怎么了?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的语句似乎缺少
cast
,因此PostgreSQL知道绑定参数是与它们相比的列的类型。同样,与
null
进行比较,应始终使用为null
。参见为什么不sql support sql support = null”而不是” null是吗?所以
应该工作。
Your statement seems to be missing a
CAST
so that Postgresql knows that the bind parameters are of the type of the columns they get compared to.Also comparisons with
NULL
should always be made withIS NULL
. See Why doesn't SQL support "= null" instead of "is null"?So something like
should work.
就我而言:Java(与Joda Time),Hibernate和Postgresql。
为了解决它,只需使用此处所述的实体类中提供的解决方案:Joda Time Hibernate用户指南。
https://www.joda.org/joda time-hibernate/joda time-hibernate/userguide。 html
源代码:github -Joda Time Hibernate
https://github.com/jodaorg/jodaorg/joda time-hibernate
Maven:Joda Time Hibernate在Maven存储库上
https://mvnrepository.com/artifact/artifact/joda time/joda time-time-pime-ima-po.冬眠
In my case: Java (with Joda-Time), Hibernate, and PostgreSQL.
To resolve it, simply use the solution provided in your entity class as described here: Joda-Time Hibernate User Guide.
https://www.joda.org/joda-time-hibernate/userguide.html
Source code: GitHub - Joda-Time Hibernate
https://github.com/JodaOrg/joda-time-hibernate
Maven: Joda-Time Hibernate on Maven Repository
https://mvnrepository.com/artifact/joda-time/joda-time-hibernate
就我而言,只要我需要使用可能为null的变量,我都会使用
cast(:starttime作为文本)
示例:
and(cast(:启动时间为文本)为null或cb.starttime<:starttime)
In my case, whenever I need to use a variable that might be null, I use
cast(:startTime as text)
Example :
AND (cast(:startTime as text) IS NULL OR cb.startTime < :startTime)