问题
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