What is the difference between org.hibernate.context.JTASessionContext and 开发者_如何转开发org.hibernate.context.ThreadLocalSessionContex?
With ThreadLocalSessionContext, the current session (sessionFactory.getCurrentSession()) is created and stored in a ThreadLocal. This works in any environment, because ThreadLocal is JavaSE.
JTASessionContext binds the current session to a JTA transaction. The JTA transaction provides a hook for cleanup, unlike the thread local. This is available in environments that have JTA, such as an application server.
This all is explained in the javadocs of the two classes. here and here
These strategies control behaviour of SessionFactory.getCurrentSession() by defining the scope of the current session.
- JTASessionContextassociates current session with the current JTA transaction and closes it at the end of JTA transaction. This strategy is used in JTA-capable environments, i.e. in application servers.
- ThreadLocalSessionContextassociates current session with the current thread and closes it at the end of transaction created in that session. It's for use in standalone environments.
By the way, javadoc and reference describe it pretty clear.
See also:
- 2.3. Contextual sessions
- JTASessionContext
- ThreadLocalSessionContext
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论