gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:02:06 25 4
gpt4 key购买 nike

我正在使用 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 的错误吗?

更新:
我将 Play 版本从 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



没有人有这个错误吗?

最佳答案

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

jpa.dialect=org.hibernate.dialect.PostgreSQLDialect

关于hibernate - 为什么字符串需要 Hibernate JPQL 类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8442294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com