这是由于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;
}
在查询中做事务处理可以保证读一致性和隔离性。
本文探讨了使用Hibernate过程中遇到的缓存问题,并提供了一种解决方案:通过在查询时增加事务提交操作来确保数据的一致性和隔离性。
564

被折叠的 条评论
为什么被折叠?



