-1

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!

Ricky
  • 2,662
  • 5
  • 25
  • 57
  • seems like there is issue in setting the parameter . Change this query.setParameter("date", dates); to query.setParameter("transactionDate", dates); – Harmandeep Singh Kalsi Jul 07 '20 at 06:36
  • You wrote `:transactionDate` but then you try to replace the parameter `dates`. Try to change `:transactionDate` in `:dates`. You may also need to use parenthesis around the list `(:dates)` – FaltFe Jul 07 '20 at 06:37

2 Answers2

1

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();
}
Harmandeep Singh Kalsi
  • 3,315
  • 2
  • 14
  • 26
0

Replace line

query.setParameter("dates", dates);

with

query.setParameter("transactionDate", dates);

typo issue

Rahul Kumar
  • 362
  • 1
  • 7