我正在使用spring mvc 3.2和hibernate 3.6.3构建web应用程序。我在我的DAO类中使用了HibernateDaoSupport类。现在我想更新一个实体,使用session.update()其中我从hibernateDaoSupport方法获得会话getSession()。我在这也使用交易。 但是在提交事务之后,更新没有反映在数据库中。但是如果我在提交之前使用session.flush(),那么它会得到反映。因为我知道transaction.commit在提交之前调用flush,那么为什么它没有更新记录。我没有在我的应用程序上下文中使用任何事务管理器,然后如何使用hibernatedaosupport管理事务。当一个新的会话将在我的应用程序中打开,因为getSession方法检查当前事务的会话,如果发现它然后返回那个新的。那么这意味着每个http请求中都会打开一个新的hibernate会话呢?session.update()或session.save()的数据没有反映在数据库中?
吾道守则 -
public Map<String, Object> addImmunizationCard(Box box,
Map<String, Object> dataMap) {
Session session = (Session) getSession();
Map<String, Object> map = new HashMap<String, Object>();
Transaction tx = null;
try {
tx = session.beginTransaction();
MasBed bed = (MasBed)session.get(MasBed.class, new Integer(1101));
System.out.println(bed.getBedNo());
bed.setBedNo("Amit Das");
session.update(bed);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}
return map;
}
这意味着,如果我调用session.save后运行session.createCriteria,那么它会自动提交? –
我不这么认为.. createcriteria不执行查询,也应该明确地完成提交,除非你有自动提交设置 – OTM