In Grails how do I access the hibernate session inside of a domain class static method?

后端 未结 3 1135
借酒劲吻你
借酒劲吻你 2021-02-03 12:44

I\'ve read various articles on the web, but they seem rather scattered on this point. Exactly what do I need to do in my configuration and in my method to get the hibernate ses

3条回答
  •  天命终不由人
    2021-02-03 12:53

    From a static method you can pull the sessionFactory bean from the application context:

    import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
    ...
    def ctx = AH.application.mainContext
    def sessionFactory = ctx.sessionFactory
    def session = sessionFactory.currentSession
    

提交回复
热议问题