【发布时间】:2012-08-24 03:49:49
【问题描述】:
我使用 Spring Data JPA 和 hibernate 作为持久性提供程序。 PostgreSQL 9.1.5 是我的数据库。
查询:
@Query("select COUNT(u) from User u where u.enabled=true")
自动翻译成
select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=1
如您所见,“true”被“1”取代。 Postgre 不接受这个查询并抛出错误:
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
无需替换的查询工作正常。在 pgadmin 查询界面中,以下查询有效。
select count(user0_.username) as col_0_0_ from users user0_ where user0_.enabled=true
我该如何解决这个问题?
【问题讨论】:
-
您使用哪个持久性提供程序(Hibernate?EclipseLink?OpenJPA?)以及
User.enabled的映射是什么样的?您的 ORM 配置中是否设置了正确的数据库方言? -
我使用 ProgressDialect 而不是 PostgreSQLDialect。感谢您的提示。
标签: spring-data-jpa