Issue occurs on Spring Boot 3.0.6 with core hibernate 6.4.3.Final and 6.1.7.Final.
Issue is specifically a query checking if a string returned from a column is in a list supplied as a parameter:
@Repository
public interface BalanceRepository extends JpaRepository<Balance, Long> {
@Query(value = "" +
"select new com.xyzcorp.finance.paymentgateway.dto.BillingRecordDto(" +
"record.billNumber, " +
"record.fiscalWeek, " +
"record.fiscalYear, " +
"record.billDate, " +
"record.recordStatus, " +
"record.moneyType, " +
"record.vendorId, " +
"record.vendorName, " +
"record.paymentAddressName, " +
"record.paymentAddressLine1, " +
"record.paymentAddressLine2, " +
"record.paymentAddressZip, " +
"record.paymentAddressTown, " +
"record.paymentAddressCountry, " +
"record.closeTime, " +
"record.dispatchTime) " +
"from BillingRecord record " +
"where 1=1 " +
"and (:fiscalWeek is null or record.fiscalWeek = :fiscalWeek) " +
"and (:fiscalYear is null or record.fiscalYear = :fiscalYear) " +
"and (:recordStatus is null or record.recordStatus = :recordStatus) " +
"and (:vendorId is null or record.vendorId = :vendorId) " +
"and (:billNumber is null or record.billNumber = :billNumber) " +
"and (:orderNumber is null or record.billNumber in " +
"(select deal.billId from Deal deal where deal.orderId = :orderNumber)) " +
"and (:dispatched is null or (:dispatched = true and record.dispatchTime is not null) or (:dispatched = false and record.dispatchTime is null)) " +
"and (:moneyType is null or (:moneyTypeIncluded = true and record.moneyType in :moneyType) or (:moneyTypeIncluded = false and record.moneyType not in :moneyType)) " +
"and (:ledgerExportId is null or record.ledgerExportId = :ledgerExportId)")
List<BillingRecordDto> fetchBillingRecords(@Param("fiscalWeek") Integer fiscalWeek,
@Param("fiscalYear") Integer fiscalYear,
@Param("recordStatus") BillStatus recordStatus,
@Param("vendorId") Long vendorId,
@Param("billNumber") Long billNumber,
@Param("orderNumber") Long orderNumber,
@Param("dispatched") Boolean dispatched,
@Param("moneyType") List<String> moneyType,
@Param("moneyTypeIncluded") Boolean moneyTypeIncluded,
@Param("ledgerExportId") Long ledgerExportId);
Which throws an error, inconsistently, in Hibernate
2024-02-08 17:14:01,775 ERROR [http-nio-8081-exec-2 ] org.apache.juli.logging.DirectJDKLog: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [[GBP]] did not match expected type [SqmBasicValuedSimplePath(com.xyzcorp.finance.paymentgateway.dto.BillingRecord(BillingRecord).moneyType)]] with root cause
org.hibernate.HibernateException: Could not convert 'java.util.ArrayList' to 'java.lang.String' using 'org.hibernate.type.descriptor.java.StringJavaType' to wrap
To be precise moneyType here in the object is a string.
Taking out the list and doing a search by single parameter with = works fine.
This seems to be the same issue as descrbied here java - Exception thrown in jpa query with List parameter after Spring Boot 3 upgrade - Stack Overflow but I can’t find any topic on it here. Likewise this should be a legal operation with an example here JPA + Hibernate - JPQL IN Expression Example.
If it helps its an Oracle DB but I don’t think that’s relevant. Can anyone let me know if the sytax has somehow changed or if this is a known bug with still no solution yet.