I use Spring Data JPA with hibernate as persistence provider. PostgreSQL 9.1.5 is my database.
Query:
@Query("select COUNT(u) from User u where u.enabled=true")
is automatically translated to
select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=1
As you can see “true” is replaced by “1”. Postgre does’t accept this query and error is thrown:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=1]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
Query without replacement works fine. In pgadmin query interface the following query works.
select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=true
How can I fix this problem?
Make sure you are using correct database dialect in your JPA provider. E.g. in Hibernate it should be: