廣告

2016年3月28日 星期一

Hibernate openSession() vs getCurrentSession()


      SessionFactory.openSession():
      always opens a new session that you have to
      close once you are done with the operations.
     
      SessionFactory.getCurrentSession():
      returns a session bound to a context - you don't need to close this. 
     
      should always use "one session per request" or "one session per transaction"
      In one application, if the DAO layer, using Spring hibernate,
      control the life cycle via Spring session to ,

      First choice  getCurrentSession ().

沒有留言:

張貼留言