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

后端 未结 3 1114
借酒劲吻你
借酒劲吻你 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 13:09

    If it's in a service or controller, you just need to declare sessionFactory

    def sessionFactory

    to have it injected. After that you can refer to

    sessionFactory.currentSession
    

    to use it.

    Check out hibernate-filter plugin (file HibernateFilterGrailsPlugin.groovy) for how to inject a bunch of methods that use the session.

提交回复
热议问题