Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么字符串需要Hibernate JPQL类型转换_Hibernate_Playframework_Jpa 2.0_Jpql - Fatal编程技术网

为什么字符串需要Hibernate JPQL类型转换

为什么字符串需要Hibernate JPQL类型转换,hibernate,playframework,jpa-2.0,jpql,Hibernate,Playframework,Jpa 2.0,Jpql,我在用这个剧本!一个小型应用程序的框架。在模型中,我有以下查询: public static ApplicationUser getByUserName(String userName) { return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = ?", userName).first(); } 这对内存中的DB H2非常有效,但当我使用Postgres时,我会出现以下错误: 22:

我在用这个剧本!一个小型应用程序的框架。在模型中,我有以下查询:

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.dialogue=org.hibernate.dialogue.PostgreSqlDialogue


没有人出现此错误?

您是否在conf/application.conf中启用了postgresql数据库方言

jpa.dialogue=org.hibernate.dialogue.PostgreSqlDialogue

是否尝试替换?通过(?1),如:

我有一个类似的问题,工作得很好。我假设ApplicationUser中的字段用户名是String类型(以防万一!)


此外,正如Dominik所建议的,检查您的jpa.dial是否设置为自动发现或PosgreSQL。

我遇到了完全相同的问题,1.2.4

User.find("byEmail", email).first()
获得与您完全相同的施法错误,因此我必须将其替换为(感谢Pere)

有趣的是

User.find("byEmailAndPassword", email, password).first()

仍然有效…

请参阅我的更新。我已将播放从1.2.4降级到1.2.3,现在一切正常。请参阅我的更新。我已经把比赛从1.2.4降到了1.2.3,现在一切都很好,这对我很有帮助。谢谢对不起,我迟了答复
User.find("email = (?1)", email).first()
User.find("byEmailAndPassword", email, password).first()