【问题标题】:Hibernate HQL could not locate named parameterHibernate HQL 找不到命名参数
【发布时间】:2017-12-30 01:54:55
【问题描述】:
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();

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

【问题讨论】:

    标签: java spring hibernate hql


    【解决方案1】:

    尝试删除参数上的单引号

    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();
    

    【讨论】:

    • 不,它会给出classcastException。
    • @Jayesh 我认为它返回 List 而不是 List 这就是你得到 classCastException 的原因。确保首先尝试调试它
    猜你喜欢
    • 2017-11-21
    • 2012-10-02
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 2012-07-30
    相关资源
    最近更新 更多