沉睡森林@漂在北京

本处文章除注明“转载”外均为原创,转载请注明出处。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  152 随笔 :: 4 文章 :: 114 评论 :: 0 Trackbacks

问题描述:

Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition. 

posted on 2009-05-21 20:28 王总兵 阅读(196) 评论(1)  编辑  收藏 所属分类: Spring

评论

# re: Spring和Hibernate结合时遇到的问题 2009-05-21 20:30 王兵
下面是转自【http://www.blogjava.net/i369/articles/240039.html
一般这个错误是事务引起的,如果确定事务没有问题,还是有这个错,可以重写OpenSessionInViewFilter的2个方法
在myfaces的wiki里提供了OpenSessionInViewFilter的一个子类如下:
public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {

/**
* we do a different flushmode than in the codebase
* here
*/
protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
session.setFlushMode(FlushMode.COMMIT);
return session;
}
/**
* we do an explicit flush here just in case
* we do not have an automated flush
*/
protected void closeSession(Session session, SessionFactory factory) {
session.flush();
super.closeSession(session, factory);
}
}
  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: