Spring Boot data-jpa和nativeQuery Postgres演员表 [英] Spring Boot data-jpa and nativeQuery Postgres cast
本文介绍了Spring Boot data-jpa和nativeQuery Postgres演员表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在如下所示的存储库中有一个自定义@Query
:
I have a custom @Query
in a repository that looks like this:
SELECT * FROM topicaudit_c14001
WHERE auditdate >= NOW()
AND auditdate <= NOW() + '1 hour'::INTERVAL
AND accepted_status = 'ACCEPTED'
AND reminder_sent = FALSE
运行此命令时,出现异常:
When I run this, I get the exception:
org.hibernate.QueryException:
Not all named parameters have been set: [:INTERVAL]
显然,它会将::INTERVAL
强制转换(Postgresql)解释为命名参数,并且由于我不提供参数而无法触发查询.
Obviously it is interpreting the ::INTERVAL
cast (Postgresql) as a named parameter and cannot fire the query since I don't provide a parameter.
如何编写此查询以使其与JPA一起使用?
How can I write this query so that it works with JPA?
推荐答案
发布后不久我发现了它.逃避::
帮助.
I found it out shortly after posting. Escaping the ::
helps.
SELECT * FROM topicaudit_c14001
WHERE auditdate >= NOW()
AND auditdate <= NOW() + '1 hour'\\:\\:INTERVAL
AND accepted_status = 'ACCEPTED'
AND reminder_sent = FALSE
这篇关于Spring Boot data-jpa和nativeQuery Postgres演员表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文