hibernate 锁查询

action:
List<User> result = (List<User>) = dao.queryLock("from User po where id=?", LockMode.UPGRADE,"1");

dao:
public Object queryLock(final String hql, final LockMode lockMode, final Object... params) {
    return this.getHibernateTemplate().execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            Query query = session.createQuery(hql);
            for (int i = 0; i < params.length; i++) {
                query.setParameter(i, params[i]);
            }
            query.setLockMode("po", lockMode);
            return query.list();
        }
    });
}


你可能感兴趣的:(DAO,Hibernate,session,object,query,action)