【发布时间】:2012-01-16 13:21:47
【问题描述】:
我正在使用 Play!小型应用程序的框架。在模型中,我有以下查询:
public static ApplicationUser getByUserName(String userName) {
return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = ?", userName).first();
}
这与内存中的 DB 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 驱动程序上。
更新二:问题仍未解决。我再次收到同样的查询错误:
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
没有人遇到这个错误?
【问题讨论】:
标签: hibernate playframework jpa-2.0 jpql