HTTP Status 500 - 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.


HTTP Status 500 - 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. type Exception report message Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTOor remove 'readOnly' marker from transaction definition.

description The server encountered an internal error that prevented it from fulfilling this request. exception 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.

org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1126) org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:619) org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:616) org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:341)

 .....

HTTP狀態500-寫入操作不允許在只讀模式(FlushMode.MANUAL)中進行:將會話轉換為FlushMode.COMMIT/AUTO,或從事務定義中刪除“readOnly”標記。

錯誤原因:

代碼中使用了@Transactional注解事務,因為你沒有在applicationContext.xml中配置事務自動掃描,而使用了默認的只讀模式,不能隨代碼運行自動刷新,

更正方法:

在applicationContext.xml文件中增加配置:

    <!--配置事務管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 開啟事務掃描,采用注解方式 -->
    <tx:annotation-driven transaction-manager="transactionManager" />

每天分享一個錯誤,快樂成長每一天!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM