2

永続性プロバイダーとしてHibernateでSpringDataJPAを使用しています。PostgreSQL9.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

この問題を解決するにはどうすればよいですか?

4

1 に答える 1

1

JPA プロバイダーで正しいデータベースの方言を使用していることを確認してください。たとえば、休止状態では次のようになります。

org.hibernate.dialect.PostgreSQLDialect
于 2012-08-30T07:43:32.370 に答える