简体   繁体   English

在 JPA 命名查询中使用 postgres 函数“lower”时出错

[英]Getting error from using postgres function "lower" in JPA Named Queries

Any idea why hibernate is complaining about the typecasting?知道为什么 hibernate 会抱怨类型转换吗? I am already passing in as a String to the function.我已经作为字符串传递给函数。 I am using @Query syntax with named parameters.我正在使用带有命名参数的 @Query 语法。 Is it okay to have lower function embedded inside the query?在查询中嵌入较低的函数可以吗?

Source Code:源代码:

@Query("from UserEntity t where lower(t.email) = lower(:email)")
List<UserEntity> findByEmail(@Param("email") String email);

Error:错误:

Caused by: org.postgresql.util.PSQLException: ERROR: function lower(bytea) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 899

nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

Related Link: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters相关链接: https : //docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters

I finally understood what is happening.我终于明白是怎么回事了。 I was getting the error because when I called the function findByEmail , in some cases email was null which is causing the postgres to complain.我收到错误是因为当我调用函数findByEmail ,在某些情况下 email 为null ,这导致 postgres 抱怨。 I just needed to check for null before call this function.我只需要在调用这个函数之前检查null Thanks @akshar-patel for trying to help.感谢 @akshar-patel 尝试提供帮助。

I finally understood what is happening.我终于明白是怎么回事了。 I was getting the error because when I called the function findByEmail, in some cases email was null which is causing the problem我收到错误是因为当我调用函数 findByEmail 时,在某些情况下电子邮件为空,这导致了问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM