javahibernatespring-mvcjpahibernateexception

How to query from a date list in JPA?


I am trying to query all the transactions happened from a list of dates.So I tried the below function:

 public Collection<Transaction> getTransactionsByDates(short status,List<Date> dates){
   Query query = em.createQuery(" SELECT a FROM Transaction a where a.Status=:status and a.dates in :transactionDate");
   query.setParameter("status", status);
   query.setParameter("dates", dates);
   return (Collection<Transaction>) query.getResultList();
}

But this throws the error of

org.hibernate.QueryException: could not resolve property: dates

Am I querying in JPA properly?

Any help is appreciated!


Solution

  • I think there is typo

    public Collection<Transaction> getTransactionsByDates(short status,List<Date> dates){
       Query query = em.createQuery(" SELECT a FROM Transaction a where a.Status=:status and a.dates in :transactionDate");
       query.setParameter("status", status);
       query.setParameter("transactionDate", dates);
       return (Collection<Transaction>) query.getResultList();
    }