【发布时间】:2013-05-18 14:49:20
【问题描述】:
我对 Grails 中的 withSession 和当前休眠会话感到困惑。
我的问题是:我们在闭包中可以访问的会话对象是否与当前休眠会话对象相同?
我写了一个Service,其动作如下:
def strangeBehavior(){
Link.withSession { session->
println "link current session " + session.hashCode()
}
Task.withSession { session->
println "task current session " + session.hashCode()
}
Project.withSession { session->
println "project current session " + session.hashCode()
}
UserStory.withSession { session->
println "user story current session " + session.hashCode()
}
def ctx = AH.application.mainContext
def sessionFactory = ctx.sessionFactory
def tmp = sessionFactory.currentSession
println " current session " + tmp.hashCode()
}
}
对我来说奇怪的是有 5 个不同的哈希码...如果我打印 5 个会话对象,我会看到相同的 toString() 结果。这让我猜测它们具有相同的内容:
SessionImpl(PersistenceContext[entityKeys=[EntityKey[com.astek.agileFactory.Link#170], EntityKey[com.astek.agileFactory.Project#9]],collectionKeys=[Col……”
【问题讨论】:
-
不,抱歉让你混淆了,事实上,我刚刚写了一个普通的服务,它有一个名为strangeBehavioi()的动作,我用run-app运行我的应用程序。