As stated in the title, I'm facing this issue when optional paramter(endDate) is null. It doesn't throw any error when both parameters are provided. I tried usin cast null as timestamp with time zone, cast as timestamp to both params in the query and it throws the same error. Please advise.
@Query("""
SELECT setspanyId, COUNT(sets)
FROM WarehouseSetsEntity sets
WHERE (:endDate IS NULL AND sets.importDate >= :beginDate)
OR (:endDate IS NOT NULL AND sets.importDate BETWEEN :beginDate AND :endDate)
GROUP BY setspanyId""")
List<Object[]> fetchCompanyByDateRange(@Param("beginDate") OffsetDateTime beginDate, @ Param("endDate") @NullableOffsetDateTime endDate);
Error:.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL [select wse1_0panyid,count(wse1_0.setid) from sets wse1_0 where (coalesce(?,'1970-01-01T00 00:00Z') is null and wse1_0.import_date>=?) or (? is not null and wse1_0.import_date between ? and ?) group by wse1_0panyid] [ERROR: could not determine data type of parameter $3] [n/a]; SQL [n/a]
As stated in the title, I'm facing this issue when optional paramter(endDate) is null. It doesn't throw any error when both parameters are provided. I tried usin cast null as timestamp with time zone, cast as timestamp to both params in the query and it throws the same error. Please advise.
@Query("""
SELECT setspanyId, COUNT(sets)
FROM WarehouseSetsEntity sets
WHERE (:endDate IS NULL AND sets.importDate >= :beginDate)
OR (:endDate IS NOT NULL AND sets.importDate BETWEEN :beginDate AND :endDate)
GROUP BY setspanyId""")
List<Object[]> fetchCompanyByDateRange(@Param("beginDate") OffsetDateTime beginDate, @ Param("endDate") @NullableOffsetDateTime endDate);
Error:.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL [select wse1_0panyid,count(wse1_0.setid) from sets wse1_0 where (coalesce(?,'1970-01-01T00 00:00Z') is null and wse1_0.import_date>=?) or (? is not null and wse1_0.import_date between ? and ?) group by wse1_0panyid] [ERROR: could not determine data type of parameter $3] [n/a]; SQL [n/a]
Share
edited Mar 10 at 23:53
ilaunchpad
asked Mar 10 at 23:44
ilaunchpadilaunchpad
1,3333 gold badges17 silver badges32 bronze badges
1 Answer
Reset to default 1Can you try using below code?
WHERE sets.importDate >= :beginDate AND (sets.importDate <= :endDate OR :endDate IS NULL)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744819498a4595529.html
评论列表(0条)