How to query from a date list in JPA?

343 views Asked by At

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!

2

There are 2 answers

0
Harmandeep Singh Kalsi On BEST ANSWER

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();
}
0
Rahul Kumar On

Replace line

query.setParameter("dates", dates);

with

query.setParameter("transactionDate", dates);

typo issue