【问题标题】:Curious call of merge inside un-true if case如果情况下,在不真实的情况下奇怪地调用合并
【发布时间】:2016-01-19 12:00:03
【问题描述】:

如果samplenot null 则调用merge(..) 行,而if 中的其他5 行则不调用。为什么 ****?我马上就要跳出窗外了……

class SampleService {
    def markError(def job, def prop) {
        def sample = job.getSamples().find { sample ->
             sample.getProp() == prop }
        if (sample == null) {
            log.debug("i can see this only when sample == null")
            println "i can see this only when sample == null"
            def newSample = new Sample(prop: prob)
            newSample.setJob(job)
            newSample.merge(flush: true, failOnError: true)
        }
    }
}

我已经这样做了:

  • grails 清理和 grails 编译。
  • 已删除目标文件夹和 bin 文件夹。
  • 多次重启应用。
  • 用 intellij 和 eclipse 检查。

【问题讨论】:

  • 我的 stackoverflow.com/questions/34731497/… 可以提供帮助。这里What you're seeing is Hibernate detecting that a persistent instance has been modified, and by default when the session is closed it will detect the changes and helpfully flush them to the database for you. 有意义。

标签: grails transactions grails-orm


【解决方案1】:

我被调试器误导了:该行尚未执行但已突出显示。我不知道为什么它被突出显示。

希望这可以防止其他人发疯! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-21
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多