Reputation:
I need to fetch data between two dates in a JPQL query but it doesn't work. The dates are in integer but i want to compare with Dates. Here is partial query,
Thanks!
Query query = em.createQuery
("select p1 from Profile p1, Preference p2 where
(p1.birthdate >= p2.agefrom and p1.birthdate <= p2.ageto and p2.preferenceid=:a)")
.setParameter("a", profileid);
TABLE Profile {
profileid integer,
birthdate date
}
TABLE Preference {
preferenceid integer,
agefrom integer,
ageto integer
}
Upvotes: 0
Views: 947
Reputation: 1
I don't think you can compare Date and Integer. You have to either :
Upvotes: 0
Reputation: 21981
Use BETWEEN
Query query = em.createQuery("select p1 from Profile p1, Preference p2 where
p1.birthdate BETWEEN p2.agefrom AND p2.ageto and p2.preferenceid=:a)")
Upvotes: 2