public boolean checkUserExistsWithName(String username) {
SessionFactory sf = HibernateUtil.getSessionFactory();
Session s = sf.getCurrentSession();
s.beginTransaction();
long count = (Long)s.createQuery("select count(*) from User u where u.username=:username").setString("username",username).uniqueResult();
s.getTransaction().commit();
if(count>0){
return true;
}
return false;
}
我的是因为 s.beginTransaction();忘记开启导致。