2

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

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.