[英]Hibernate JTA multiuser session-transaction mapping
我指的是https://developer.jboss.org/wiki/SessionsAndTransactions ,目前正在嘗試了解JTA的划分。 它指出在特定事務中,使用getCurrentSession()總是給出相同的當前會話。 它的意思是:
任何指針/幫助深表感謝。
謝謝
根據javadoc SessionFactory.getCurrentSession()
“當前”的確切定義由配置為使用的{@link org.hibernate.context.spi.CurrentSessionContext} impl控制。
已配置JTA,這將默認為{@link org.hibernate.context.internal.JTASessionContext}的實現。
然后您可以看到JTASessionContext javadoc及其實現。
如果在調用{@link #currentSession()}時會話尚未與當前JTA事務相關聯,則將打開一個新會話並將其與該JTA事務相關聯。
public Session currentSession() throws HibernateException {
...
final TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();
...
txn = transactionManager.getTransaction();
...
final Object txnIdentifier = jtaPlatform.getTransactionIdentifier( txn );
...
Session currentSession = currentSessionMap.get( txnIdentifier );
...
}
TransactionManager javadoc
在內部,事務管理器將事務與線程相關聯,並且此處的方法對與調用線程相關聯的事務進行操作。
因此,它與普通JDBC的會話和事務/事務划分類似(但更清楚):
換句話說,會話綁定到幕后線程,但作用域是事務,就像在JTA環境中一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.