简体   繁体   English

JPA 中的 @Query 为 STR TO DATE 提供空输出

[英]@Query in JPA is giving null output for STR TO DATE

the following query is resulting in null output for all the entries in the resulting list.以下查询导致结果列表中所有条目的输出为空。

 @Query(value="select STR_TO_DATE(sp.date,'%d-%m-%Y') from shift_plan sp where sp.date>=:leaveDate and sp.shift_type NOT IN('leaveMorning','leaveAfternoon')",nativeQuery=true)
    public List<Date> findDatesGreaterThanOrEqualToLeaveDate(@Param("leaveDate") Date leaveDate);

I have saved the date as Date type in my java code but it has been saved as varchar in my database table shift_plan.I have saved from java as follows我已在我的 java 代码中将日期保存为日期类型,但它已在我的数据库表 shift_plan 中保存为 varchar。我已从 java 保存如下

cal.setTime(sdf.parse(j + "/" + (month_num + 1) + "/" + year));
                        sp.setDate(cal.getTime());

How to get the list of actual dates here?如何在此处获取实际日期列表?

This issue got fixed after changing the datatype of date from varchar to date in database.将数据库中的日期数据类型从 varchar 更改为 date 后,此问题得到解决。 STR_TO_DATE was not required after that.之后不需要 STR_TO_DATE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM