spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Enum not supported in query

Open victorherraiz-santander opened this issue 4 years ago • 4 comments

Trying to execute the following query:

    @Query(
        """
        select * from bookings
        where 
            employee_id = :employeeId and 
            to_date >= :from and 
            from_date <= :to and 
            slot in (:slots)
        """
    )
    fun findCollisionByEmployee(
        employeeId: String,
        to: LocalDate,
        from: LocalDate,
        slots: Collection<Booking.Slot>,
    ): Booking?

It throws with this message:

org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of Booking$Slot. Use setObject() with an explicit Types value to specify the type to use.] with root cause

I tried to use a Converter<Booking.Slot, String> but it does not get executed.

The expected result should be that queries use the same converters (e.i. enum to string) as other methods

Starter: org.springframework.boot:spring-boot-starter-data-jdbc:2.5.3

victorherraiz-santander avatar Aug 07 '21 10:08 victorherraiz-santander

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

schauder avatar Aug 10 '21 09:08 schauder

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Aug 17 '21 09:08 spring-projects-issues

https://github.com/victorherraiz-santander/spring-data-jdbc-issue-1023

It works with H2 but fails with postgresql, embedded or not.

Just run the provided app to get the excepcion

victorherraiz-santander avatar Aug 23 '21 08:08 victorherraiz-santander

I couldn't run your example but I was able to create some integration tests reproducing the problem. Although I can't reproduce that it actually works with H2. It does though work with only a single argument instead of a collection.

schauder avatar Mar 17 '22 10:03 schauder