简体   繁体   中英

How to fetch today's date in CriteriaBuilder in hibernate

CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Star> criteriaQuery = builder.createQuery(A.class);
Root<Star> root = criteriaQuery.from(A.class);

I am already having MONDAY of the week and FRIDAY of the week and then check the today's date lies between MONDAY and FRIDAY of the week.

I have use before and after method thats not working for me.

Try this. use cb.currentTime() or cb.currentTimestamp()

CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<Star> criteriaQuery = builder.createQuery(A.class);
Root<Star> root = criteriaQuery.from(A.class);
// Add this condition
List<Predicate> conditions = new ArrayList<>();
conditions.add(cb.equal(root.get("Your  time column name"),cb.currentTimestamp()));
cq.where(conditions.toArray(new Predicate[]{}));
Query query=session.createQuery(cq);

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