EclipseLink不接受DateString?

时间:2014-11-25 09:09:51

标签: sql postgresql select eclipselink hql

我得到以下em查询和例外:

public List<Service> findServicesFromHelperBetween(long idPerson, String from, String to) throws DAOException {
    List<Service> servicesFromHelperBetween = new ArrayList<Service>();
    try {
        em.getTransaction().begin();
        servicesFromHelperBetween = em.createQuery("SELECT S FROM Service S WHERE S.helper.idPerson = " + idPerson + " AND S.date BETWEEN " + from
                                                           + " AND " + to).getResultList();
        em.getTransaction().commit();
    }
    catch (Exception e) {
        em.getTransaction().rollback();
        throw ExceptionBuilder.findServiceFailedInDAO(e, Service.class);
    }
    return servicesFromHelperBetween;
}

例外:

Exception Description: Syntax error parsing [SELECT S FROM Service S WHERE S.helper.idPerson = 8 AND S.date BETWEEN 01.11.2014 AND 30.11.2014]. 
[71, 73] The identification variable '01' is not following the rules for a Java identifier.
[86, 88] The identification variable '30' is not following the rules for a Java identifier.

1 个答案:

答案 0 :(得分:0)

尝试将参数放在单引号

之间
em.createQuery("SELECT S FROM Service S WHERE S.helper.idPerson = " + idPerson + " AND S.date BETWEEN '" + from
                                                           + "' AND '" + to + "'").getResultList();