Reputation: 83
I want to get records from a table where admission date is in a range, so 'datebegin' and 'endate' are in Date type, admissiondate is in Date format too.
List clients = session.createQuery("Select Id_Client from Contract contract where contract.admissiondate BETWEEN '"+ datebegin+"' and '"+endate+"'").list();
With my query i get this error:
org.hibernate.QueryException: could not resolve property: admissiondate of: bean.Contract [Select Id_Client from bean.Contract contract where contract.admissiondate BETWEEN 'Sat Feb 15 00:00:00 CET 2014' and 'Mon Mar 17 00:11:24 CET 2014']
And it said:
Conversion failed when converting date and/or time from character
Upvotes: 0
Views: 86
Reputation: 19
You aliased your contract table but it was spelt incorrectly when getting the admissiondate columns. Try the below.
List clients = session.createQuery("Select Id_Client from Contract contract where contract.admissiondate BETWEEN '"+ cast(datebegin as datetime)+"' and '"+ cast(endate as datetime)+"'").list();
Upvotes: 0
Reputation: 19
try casting it?
List clients = session.createQuery("Select Id_Client from Contract contract where contrat.admissiondate BETWEEN '"+ cast(datebegin as datetime)+"' and '"+ cast(endate as datetime)+"'").list();
Upvotes: 0