Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate JTASessionContext vs ThreadLocalSessionContext

Tags:

java

hibernate

What is the difference between org.hibernate.context.JTASessionContext and org.hibernate.context.ThreadLocalSessionContex?

like image 564
Konstantin Kudryavtsev Avatar asked Mar 06 '26 04:03

Konstantin Kudryavtsev


1 Answers

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

like image 95
Bozho Avatar answered Mar 07 '26 17:03

Bozho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!