hibernate启动起来之后,往数据库添加了一条记录,紧接着查询却查不出来刚刚添加的记录,最简单的方法就是在查询方法session.close();之前提交事物,就可以了!
public boolean loginValidate(Member member) { Query query = session.createQuery("from Member where mname=? and mpass=?"); System.out.println(member.getMname() + " " + member.getMpass()); query.setString(0, member.getMname()); query.setString(1, member.getMpass()); Member mb = (Member) query.uniqueResult(); if (null != mb) { flag = true; } // 从这里提交一下事物就可以查询出刚刚添加到数据库里的记录了 session.beginTransaction().commit(); session.close();}