[英]Hibernate JTA multiuser session-transaction mapping
I am referring to https://developer.jboss.org/wiki/SessionsAndTransactions and currently trying to understand demarcation with JTA. 我指的是https://developer.jboss.org/wiki/SessionsAndTransactions ,目前正在尝试了解JTA的划分。 It states that within a particular transaction using getCurrentSession() always gives the same current session.
它指出在特定事务中,使用getCurrentSession()总是给出相同的当前会话。 Does it mean:
它的意思是:
Any pointers/help is much appreciated. 任何指针/帮助深表感谢。
Thanks 谢谢
According to javadoc SessionFactory.getCurrentSession() 根据javadoc SessionFactory.getCurrentSession()
The definition of what exactly "current" means controlled by the {@link org.hibernate.context.spi.CurrentSessionContext} impl configured for use.
“当前”的确切定义由配置为使用的{@link org.hibernate.context.spi.CurrentSessionContext} impl控制。
JTA is configured this will default to the {@link org.hibernate.context.internal.JTASessionContext} impl.
已配置JTA,这将默认为{@link org.hibernate.context.internal.JTASessionContext}的实现。
Then you can see JTASessionContext javadoc and implementation. 然后您可以看到JTASessionContext javadoc及其实现。
If a session is not already associated with the current JTA transaction at the time {@link #currentSession()} is called, a new session will be opened and it will be associated with that JTA transaction.
如果在调用{@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 TransactionManager javadoc
Internally, the transaction manager associates transactions with threads, and the methods here operate on the transaction associated with the calling thread.
在内部,事务管理器将事务与线程相关联,并且此处的方法对与调用线程相关联的事务进行操作。
So, it's similar (but more clearly) to Sessions and Transactions/Transaction demarcation with plain JDBC : 因此,它与普通JDBC的会话和事务/事务划分类似(但更清楚):
In other words, the session is bound to the thread behind the scenes, but scoped to a transaction, just like in a JTA environment.
换句话说,会话绑定到幕后线程,但作用域是事务,就像在JTA环境中一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.