hibernate5 SessionFactory

hibernate5 SessionFactory

@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;

hibernate5 使用openSessionsession

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()));
}
相關文章
相關標籤/搜索