java - 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);
推荐阅读
- loops - 相扑巴士站
- c# - 如何反序列化 JSON 对象,将其属性分组为 .NET Core 中的不同类型?
- python - 使用 Python 修复/读取错误的 fortran 输出(缺少指数符号中的 E)
- python - AES 密钥的内容重要吗?
- bixby - 版本 7.13.0 Bixby IDE 更新。Action .js 脚本显示为普通文本?
- sql - SQL:仅使用计数查找最小聚合
- uml - 我如何设计 UML 用例图
- java - JPA Criteria multiselect with fetch - java.lang.IllegalArgumentException: org.hibernate.QueryException
- c# - 从 JSON 字符串反序列化时,我的类没有被填充
- git - 从“分离的 HEAD”结帐后丢失 git 数据