Monday, November 30, 2015

JPA select query with timestamp and date fields fail to retrieve results

Cuando necesitemos hacer consultas con dates, tipo date, y timestamp se hace asi:


 
Date and Calendar parameter values require special methods in order to specify what they represent, such as a pure date, a pure time or a combination of date and time, as explained in detail in the Date and Time (Temporal) Types section

For example, the following invocation passes a Date object as a pure date (no time):

Query query = em.createQuery("Select f From usuarios f where f.fecha=:date");

query.setParameter("date", new java.util.Date(), TemporalType.DATE);


and timestamp

query.setParameter("date", new java.util.Date(), TemporalType.TIMESTAMP);

No comments:

Post a Comment