Spring Boot data-jpa and nativeQuery Postgres cast

…衆ロ難τιáo~ 提交于 2019-12-25 09:29:22

问题


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]

Obviously it is interpreting the ::INTERVAL cast (Postgresql) as a named parameter and cannot fire the query since I don't provide a parameter.

How can I write this query so that it works with JPA?


回答1:


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


来源:https://stackoverflow.com/questions/43982579/spring-boot-data-jpa-and-nativequery-postgres-cast

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!