Hibernate HQL无法找到命名参数

时间:2017-07-24 12:57:31

标签: java spring hibernate hql

users = (List<User>) currentSession.getCurrentSession().createQuery("FROM User as u "
            + " LEFT JOIN FETCH u.tests as p"
            +" WHERE u.registrationDate BETWEEN "
            +"':tenDaysBeforeDate' AND ':currDate' "
            +"ORDER BY u.registrationDate DESC").setParameter("tenDaysBeforeDate", tenDaysBeforeDate).setParameter("currDate", currDate).list();

缺少什么?我试图设置的参数都是字符串类型,请帮助...

1 个答案:

答案 0 :(得分:2)

尝试删除参数上的单引号

users = (List<User>) currentSession.getCurrentSession().createQuery("FROM User as u "
        + "LEFT JOIN FETCH u.patients as p "
        +"WHERE u.registrationDate BETWEEN "
        +":tenDaysBeforeDate AND :currDate "
        +"ORDER BY u.registrationDate DESC").setParameter("tenDaysBeforeDate", tenDaysBeforeDate).setParameter("currDate", currDate).list();