gpt4 book ai didi

hibernate - 使用 hibernate 返回计数值的查询

转载 作者:行者123 更新时间:2023-12-03 18:27:24 24 4
gpt4 key购买 nike

这是我的 mysql 查询:

SELECT count(*) 
FROM bw_jobs
WHERE year(job_date)=year(curdate()) AND month(job_date)=month(curdate());

如何在 hibernate 中使用它来获取计数值?

最佳答案

String hql = "select count(job.id) from Job job"
+ " where year(job.jobDate) = year(current_date())"
+ " and month(job.jobDate) = month(current_date())";
Query query = session.createQuery(hql);
return ((Number) query.uniqueResult()).intValue();

(假设bw_jobs表由Job实体映射,job_date列映射到jobDate属性)

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#queryhql-expressions获取 Hibernate 支持的功能列表。

关于hibernate - 使用 hibernate 返回计数值的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5848591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com