S2SH使用OpenSessionInViewFilter出現InvalidDataAccessApiUsageException

    org.springframework.dao.InvalidDataAccessApiUsageException: 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.java


    項目裏是基於struts二、hibernate、spring框架,,關於事務出現的異常問題使用hibernate的OpenSessionViewFilter來管理session,因此:
spring

    重寫以下:session

public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter{	/* (non-Javadoc)	 * @see org.springframework.orm.hibernate3.support.OpenSessionInViewFilter#getSession(org.hibernate.SessionFactory)	 */	@Override	protected Session getSession(SessionFactory sessionFactory) throws DataAcce***esourceFailureException {		Session session = SessionFactoryUtils.getSession(sessionFactory, true);		session.setFlushMode(FlushMode.COMMIT);		return session;	}	/* (non-Javadoc)	 * @see org.springframework.orm.hibernate3.support.OpenSessionInViewFilter#closeSession(org.hibernate.Session, org.hibernate.SessionFactory)	 */	@Override	protected void closeSession(Session session, SessionFactory sessionFactory) {		session.flush();		super.closeSession(session, sessionFactory);	}
相關文章
相關標籤/搜索