Reputation: 297
Good afternoon , I need to filter a query by date, the date is defined in the database as: y: m: d. It 's performed with sqlnativo in hibernate but it returns null. anyone can help me , also if someone can explain me how to handle criteria with dates, since I do not find any clear example
Query query = session.createSQLQuery("Select id,fecha,total,idEnvio FROM VENTA_CABECERA vc WHERE date(fecha) = :fec" ).addEntity(HeadSale.class);
query.setParameter("fec", date);
return query.list();
It can also be the between clause , but honestly I can not make it work. would be grateful to give me a solution. regards
Upvotes: 2
Views: 2369
Reputation: 7890
change the format of "fec" parameter
as y: m: d and remove date
function inside query
DateFormat df;
df= new SimpleDateFormat("y: m: d");
String dt= sdf.format(date);
Query query = session.createSQLQuery
("Select id,fecha,total,idEnvio FROM VENTA_CABECERA vc WHERE fecha = :fec" )
.addEntity(HeadSale.class);
query.setParameter("fec", dt);
return query.list();
Upvotes: 1