Description
[BUG]
Given the entity:
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID orderId;
private UUID customerId;
private String orderStatus;
// getters and setters
The following JPQL query causes errors when using the LOWER
function with strings on PostgreSQL.
@Query("""
SELECT
o
FROM
Order o
WHERE
(:customerId IS NULL OR o.customerId = :customerId)
AND
(:status IS NULL OR LOWER(o.orderStatus) = LOWER(:status))
""")
Page<Order> findOrders(
@Param("customerId") UUID customerId,
@Param("status") String status,
Pageable pageable
);
It says:
Caused by: org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL [select o1_0.order_id,o1_0.customer_id,o1_0.order_status from orders o1_0 where (? is null or o1_0.customer_id=?) and (? is null or lower(o1_0.order_status)=lower(?)) fetch first ? rows only] [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.
Current workaround is to change the query to LOWER(o.orderStatus) = LOWER(COALESCE(:status, o.orderStatus))
Setup specs:
Spring Boot version : 3.5.3
PostgreSQL version: 17.5
Java: 21
Similar issue on stackoverflow with more details and explanation: https://stackoverflow.com/questions/77881433/org-postgresql-util-psqlexception-error-function-lowerbytea-does-not-exist