【问题标题】:How should I overcome from this hibernate error of java Write operations are not allowed in read-only mode我应该如何克服这个 java 的休眠错误 在只读模式下不允许写入操作
【发布时间】:2018-01-20 16:12:30
【问题描述】:

只读模式下不允许写入操作 (FlushMode.MANUAL):将 Session 转换为 FlushMode.COMMIT/AUTO 或从事务定义中删除“readOnly”标记。 在 org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)

【问题讨论】:

    标签: java hibernate


    【解决方案1】:

    在你的弹簧上下文部分,设置以下内容。

    <!--default is required transaction-->
    <tx:method name="*"/>
    

    我认为您的当前设置为:

    <tx:method name="*" read-only="true" propagation="REQUIRED" />
    

    您还可以将@Transactional(readOnly = false) 设置为需要写入数据库的类方法(比如持久化、更新或删除等DAO 类方法)。

        @Transactional(readOnly = false)
        public void UpdateEmployee() {
          ...
          ...
        }
    

    【讨论】:

    • 请告诉我应该把这行放在哪里 在下面的配置文件中:
    • 在你的函数上方添加@Transactional。检查我的编辑部分
    猜你喜欢
    • 2011-10-12
    • 2011-12-01
    • 2014-04-26
    • 1970-01-01
    • 2015-03-14
    • 2016-12-12
    • 1970-01-01
    • 2011-07-21
    • 2014-10-03
    相关资源
    最近更新 更多