Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Any idea why hibernate is complaining about the typecasting? I am already passing in as a String to the function. I am using @Query syntax with named parameters. 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

like image 970
raym-ag Avatar asked Feb 17 '18 15:02

raym-ag


1 Answers

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. I just needed to check for null before call this function. Thanks @akshar-patel for trying to help.

like image 108
raym-ag Avatar answered Nov 10 '22 03:11

raym-ag