首页 > 解决方案 > 如何修复 SQLGrammar 异常?

问题描述

我一直在尝试查询从当前日期到过去五天的结果集,但我得到了这个异常:

Exception Caught in UsrpScheduleServiceImpl.doSchedule org.springframework.orm.jpa.JpaSystemException:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet; nested exception is javax.persistence.PersistenceException:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet

这是代码:

        SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
        Calendar now = Calendar.getInstance();
        now.add(Calendar.DATE, -5);
        java.util.Date fromDate = new java.util.Date(now.getTime().getTime());
        
        Set<String> usrpRequestSet = new HashSet<String> ();
        List<UsrpRequest> usrpRequest = usrpRequestDao.findOrdersByRequestStatus(fromDate);

这是被调用的函数:

public List<UsrpResponse> findRecordsByCreatedDate(java.util.Date fromDate) {
        
            LOGGER.debug("find Records By Created Date check  "+fromDate);
            java.sql.Date fromDate1 = new java.sql.Date(fromDate.getTime());
            LOGGER.debug("find Records By Created Date check in Sql format "+ fromDate1);
            List<UsrpResponse> resultList = find(FIND_RECORDS_BY_CREATED_DATE_SQL,fromDate1);
            
        return resultList;
    }

查询是:

 private static final String FIND_RECORDS_BY_CREATED_DATE_SQL = "SELECT c FROM UsrpResponse c WHERE c.createdDate >= ?1 and c.errorText = 'Partial Order Created.' ORDER BY c.createdDate DESC";

有人对如何解决此错误有任何想法吗?

标签: javasqlhibernatehql

解决方案


推荐阅读