如何使用 Hibernate Criteria 从 sql 日期获取月份并检查月份等于传递的参数月份
How to get month from sql date and check month is equal to the passing parameter month using Hibernate Criteria
使用下面的函数获取 sql 月份 date.But 我没有得到正确的信息,它显示异常,任何人都请帮助我
public static List<data> getCount(Long month,String activity)
{
session = HibernateUtils.getHibernateConnection();
Criteria c = session.createCriteria(Statement.class, "statement");
Criteria text = c.createAlias("activity", "activity");
c.add(Restrictions.eq("activity.defintionType",activity));
c.add(Restrictions.eq("month(statement.stored)",month));
alist= c.list();
}
更改此行:
c.add(Restrictions.eq("month(statement.stored)",month));
对此:
c.add(Restrictions.sqlRestriction("month(stored) = ? ", 1,Hibernate.INTEGER));
假设提供的月份参数是数字类型。
使用下面的函数获取 sql 月份 date.But 我没有得到正确的信息,它显示异常,任何人都请帮助我
public static List<data> getCount(Long month,String activity)
{
session = HibernateUtils.getHibernateConnection();
Criteria c = session.createCriteria(Statement.class, "statement");
Criteria text = c.createAlias("activity", "activity");
c.add(Restrictions.eq("activity.defintionType",activity));
c.add(Restrictions.eq("month(statement.stored)",month));
alist= c.list();
}
更改此行:
c.add(Restrictions.eq("month(statement.stored)",month));
对此:
c.add(Restrictions.sqlRestriction("month(stored) = ? ", 1,Hibernate.INTEGER));
假设提供的月份参数是数字类型。