0
回答
Write operations are not allowed in read-only mode (FlushMode.MANUAL):
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   

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

在使用springmvc+spring4+hibernate4搭建的项目中使用hibernateTemplate对实体进行操作(增删改)时报如上错误,

查阅资料 配置事务或者配置OpenSessionInViewFilter 都不能解决

以下是OpenSessionInViewFilter中部分源码,可以看出FlushMode为MANUAL,但并不是我们想要的

protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException { try {
        Session ex = sessionFactory.openSession();
        ex.setFlushMode(FlushMode.MANUAL); return ex;
    } catch (HibernateException var3) { throw new DataAccessResourceFailureException("Could not open Hibernate Session", var3);
    }
}

通过设置filter里的initparam,如下,但是无效

<filter>

        <filter-name>OpenSessionInViewFilter</filter-name>

        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>

        <init-param>

            <param-name>flushMode</param-name>

            <param-value>AUTO</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>OpenSessionInViewFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

求高人指点!




<无标签>
举报
Jialy
发帖于1年前 0回/122阅
顶部