简体   繁体   中英

JPQL to query java.util.Date field of entity using date portion of date time

I have an entity with a date field (java.util.Date). Normally the date is saved as for example 2012-10-19 21:29:03.000 . My database is MySQL.

Now I need to query the database, through JPQL, using strictly the date portion, ie, 2012-10-19 . How would I do that?

That can be done by giving TemporalType when setting parameter:

Date param ...
Query q = em.createQuery("SELECT a FROM EntityA a WHERE a.someDate > :param");
q.setParameter("param", param, TemporalType.DATE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM