hibernate缓存机制要清理,不然要重启服务器才能更新出来
写法:红色两句话要加
Session session = null;
try {
session = openSession();
String sql = "select person.personName, person.orgName, person.worktel, person.mobile, person.email"
+ "from EIP_PERSON person ";
if(name != null && name != "") {
sql += " where person.personName like '%" + name + "%' and person.orgName like '%" + name + "%' ";
}
Query q = session.createSQLQuery(sql);
List list = QueryUtil.list(q, getDialect(), begin, end);
session.flush();
return list;
} catch (Exception e) {
throw HibernateUtil.processException(e);
} finally {
closeSession(session);
FinderCache.clearCache(EipPerson.class.getName());
}
本文介绍了一种在Hibernate中确保数据更新同步的方法,通过在操作结束时清除缓存来避免重启服务器的情况。示例代码展示了如何使用try-finally块安全地进行数据库查询,并在完成后清理缓存。
8094

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



