我正在使用Play!一个小应用程序的框架。在模型中,我有以下查询:为什么需要为字符串Hibernate JPQL类型转换
public static ApplicationUser getByUserName(String userName) {
return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = ?", userName).first();
}
这与完全在内存数据库H2但是当我使用Postgres的我得到以下错误:
22:57:10,371 WARN ~ SQL Error: 0, SQLState: 42883
22:57:10,371 ERROR ~ ERROR: operator does not exist: character varying = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 167
当我投的参数,如:
ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = CAST(? AS string)", userName).first()
然后它工作。但为什么这是必要的。这可能是一个Hibernate的错误?
更新: 我将播放版本从1.2.4降级到1.2.3,现在它可以正常工作。我认为这个问题可能在于运送postgres jdbc驱动程序。
更新II:问题仍未解决。我再次得到了同样的错误查询:
ApplicationRole.find("byName", name).first();
错误:
JPAQueryException occured : Error while executing query SELECT u FROM ApplicationUser u WHERE u.userName = ?: ERROR: operator does not exist: character varying = bytea Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
在application.conf
我有:具有此错误
jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
没人?
看我的更新。我已经从1.2.4降级到1.2.3,现在一切正常。 – reen
现在帮助了我。谢谢。抱歉回复晚了 – reen