我在用这出戏!一个小型应用程序的框架。在模型中,我有以下查询:
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()
那就成功了。但为什么这是必要的。那会是个冬眠虫吗?
更新:我将play版本从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
没人有这个错误吗?
发布于 2011-12-11 19:36:07
尝试替换by (?1),如:
public static ApplicationUser getByUserName(String userName) {
return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = (?1)", userName).first();
}
我有一个类似的查询,而且工作很好。我假设userName字段在ApplicationUser中是字符串类型(以防万一!)
此外,正如Dominik所建议的,请检查您的jpa.dialect是否设置为自动发现或PosgreSQL。
发布于 2011-12-09 13:30:57
您是否在conf/application.conf中启用了postgresql数据库方言?
jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
发布于 2012-01-17 10:20:58
我也有同样的问题,1.2.4。
User.find("byEmail", email).first()
获取与您完全相同的抛出错误,因此我不得不用(谢谢Pere)替换它。
User.find("email = (?1)", email).first()
有趣的是,
User.find("byEmailAndPassword", email, password).first()
仍然有效..。
https://stackoverflow.com/questions/8442294
复制相似问题