hibernate5 SessionFactory
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
hibernate5 使用openSession
public int getCount(final String hql, final Object[] params) {
Query query = sessionFactory.openSession().createQuery(hql);
if (params != null && params.length > 0) {
for (int i = 0; i < params.length; i++) {
query.setParameter(i, params[i]);
}
}
return Integer.parseInt(String.valueOf(query.uniqueResult()));
}