Date format in select

0

I have this method:

    public List<LoteEnvEntity> findallByDate(java.util.Date dataDe, java.util.Date dataAte) {
    String strQuery = "SELECT L FROM LoteEnvEntity as L WHERE 1=1";
    //SimpleDateFormat simpledate = new SimpleDateFormat("yyyy-dd-MM");
    Query query = getEntityManager().createQuery(strQuery);     
    if (dataDe != null)
    {
        strQuery += " and L.dateEnvio >= :dataDe";// + simpledate.format(dataDe);
        query.setParameter(":dataDe", dataDe);
    }

    if (dataAte != null)
    {
        strQuery += " and L.dateEnvio <= :dataAte"; //+ simpledate.format(dataAte);
        query.setParameter(":dataAte", dataAte);
    }           

    return (List<LoteEnvEntity>) query.getResultList();     
} 

In the console, an error appears in the convert date as the date comes in the following format: "Wed Nov 05 00:00:00 BRST 2014". I need to use it in the Entity select , as you can see I already tried to use SimpleDateFormat .

    
asked by anonymous 06.11.2014 / 11:37

1 answer

1

Use the following code:

query.setParameter("dataDe", dataDe, TemporalType.DATE);
    
06.11.2014 / 12:04