【发布时间】:2016-01-19 12:00:03
【问题描述】:
如果sample 是not 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