这是由于hibernate的缓存问题。
解决方法:在用hibernate查询时,增加事务提交操作。
SessionFactory sf=getSessionFactory();
Session session=sf.openSession();
Transaction tx= session.beginTransaction();
try {
List results= session.createQuery(query).list();
tx.commit();
session.close();
return results;
} catch (RuntimeException re) {
tx.rollback();
throw re;
}
在查询中做事务处理可以保证读一致性和隔离性。