I am confused between withSession in Grails and the current hibernate session.
My question is: is there a session object that we have access to in closure that is the same as the current sleep mode session object?
I wrote a Service that has an action as shown below:
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() } }
What is strange to me is that there are 5 different hash codes ... If I print 5 session objects, I see the same result toString (). This makes me guess that they have the same content:
SessionImpl (PersistenceContext [entityKeys = [EntityKey [com.astek.agileFactory.Link # 170], EntityKey [com.astek.agileFactory.Project # 9]], collectionKeys = [Coll ...... "
source share