Reputation: 251
I am using Hibernate and JPA in my project. I use below code to return list of objects but it return empty list when i use sql in mysql it's worked correctly.
Query query=entityManager.createNativeQuery("select tools.* from tools where (SELECT DATEDIFF(:user_date,calibDate) AS DiffDate) < :diff",Tools.class);
query.setParameter("user_date",userDate);
query.setParameter("diff",day);
return query.getResultList();
anybody can help to spot what is wrong?
Upvotes: 1
Views: 2171
Reputation: 26552
Your query should look like this:
Query query=entityManager.createNativeQuery("select tools.* from tools where (SELECT DATEDIFF(:user_date,calibDate) AS DiffDate) < :diff",Tools.class);
query.setParameter("user_date",userDate, TemporalType.DATE);
query.setParameter("diff",day);
return query.getResultList();
TemporalType.DATE should be added to the 'user_date' parameter
Upvotes: 2