public class

JTATransactionFactory

extends Object
implements TransactionFactory
java.lang.Object
   ↳ org.hibernate.transaction.JTATransactionFactory

Class Overview

Factory for JTATransaction instances.

To be completely accurate to the JTA spec, JTA implementations should publish their contextual UserTransaction reference into JNDI. However, in practice there are quite a few stand-alone implementations intended for use outside of J2EE/JEE containers and which therefore do not publish their UserTransaction references into JNDI but which otherwise follow the aspects of the JTA specification. This TransactionFactory implementation can support both models.

For complete JTA implementations (including dependence on JNDI), the UserTransaction reference is obtained by a call to resolveInitialContext(Properties). Hibernate will then attempt to locate the UserTransaction within this resolved InitialContext based on the namespace returned by resolveUserTransactionName(Properties).

For the so-called stand-alone implementations, we do not care at all about the JNDI aspects just described. Here, the implementation would have a specific manner to obtain a reference to its contextual UserTransaction; usually this would be a static code reference, but again it varies. Anyway, for each implementation the integration would need to override the getUserTransaction() method and return the appropriate thing.

Summary

Constants
String DEFAULT_USER_TRANSACTION_NAME
Fields
protected InitialContext initialContext
protected String userTransactionName
Public Constructors
JTATransactionFactory()
Public Methods
boolean areCallbacksLocalToHibernateTransactions()
Are all transaction callbacks local to Hibernate Transactions? Or can the callbacks originate from some other source (e.g.
void configure(Properties props)
Configure this transaction factory.
Transaction createTransaction(JDBCContext jdbcContext, TransactionFactory.Context transactionContext)
Begin a transaction and return the associated Transaction instance.
ConnectionReleaseMode getDefaultReleaseMode()
Get the default connection release mode.
boolean isTransactionInProgress(JDBCContext jdbcContext, TransactionFactory.Context transactionContext, Transaction transaction)
Determine whether an underlying transaction is in progress.
boolean isTransactionManagerRequired()
Do we require access to the JTA TransactionManager for this strategy?
Protected Methods
InitialContext getInitialContext()
Getter for property 'initialContext'.
UserTransaction getUserTransaction()
Get the UserTransaction reference.
String getUserTransactionName()
Getter for property 'userTransactionName'.
final InitialContext resolveInitialContext(Properties properties)
Given the lot of Hibernate configuration properties, resolve appropriate reference to JNDI InitialContext.
final String resolveUserTransactionName(Properties properties)
Given the lot of Hibernate configuration properties, resolve appropriate JNDI namespace to use for UserTransaction resolution.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.transaction.TransactionFactory

Constants

public static final String DEFAULT_USER_TRANSACTION_NAME

Constant Value: "java:comp/UserTransaction"

Fields

protected InitialContext initialContext

protected String userTransactionName

Public Constructors

public JTATransactionFactory ()

Public Methods

public boolean areCallbacksLocalToHibernateTransactions ()

Are all transaction callbacks local to Hibernate Transactions? Or can the callbacks originate from some other source (e.g. a JTA Synchronization).

Returns
  • true if callbacks only ever originate from the Hibernate Transaction; false otherwise.

public void configure (Properties props)

Configure this transaction factory. Specifically here we are attempting to resolve both an InitialContext as well as the JNDI namespace for the UserTransaction.

Parameters
props The configuration properties

public Transaction createTransaction (JDBCContext jdbcContext, TransactionFactory.Context transactionContext)

Begin a transaction and return the associated Transaction instance.

Parameters
jdbcContext The jdbc context to which the transaction belongs
transactionContext The contract regarding the context in which this transaction will operate.
Returns
  • Transaction

public ConnectionReleaseMode getDefaultReleaseMode ()

Get the default connection release mode.

Returns
  • The default release mode associated with this strategy

public boolean isTransactionInProgress (JDBCContext jdbcContext, TransactionFactory.Context transactionContext, Transaction transaction)

Determine whether an underlying transaction is in progress.

Mainly this is used in determining whether to register a synchronization as well as whether or not to circumvent auto flushing outside transactions.

Parameters
jdbcContext The JDBC context
transactionContext The transaction context
transaction The Hibernate transaction
Returns
  • true if an underlying transaction is know to be in effect.

public boolean isTransactionManagerRequired ()

Do we require access to the JTA TransactionManager for this strategy?

Returns
  • True if this strategy requires access to the JTA TransactionManager; false otherwise.

Protected Methods

protected InitialContext getInitialContext ()

Getter for property 'initialContext'.

Returns
  • Value for property 'initialContext'.

protected UserTransaction getUserTransaction ()

Get the UserTransaction reference.

Returns
  • The appropriate UserTransaction reference.

protected String getUserTransactionName ()

Getter for property 'userTransactionName'. The algorithm here is

Returns
  • Value for property 'userTransactionName'.

protected final InitialContext resolveInitialContext (Properties properties)

Given the lot of Hibernate configuration properties, resolve appropriate reference to JNDI InitialContext.

In general, the properties in which we are interested here all begin with hibernate.jndi. Especially important depending on your environment are hibernate.jndi.url and hibernate.jndi.class

Parameters
properties The Hibernate config properties.
Returns
  • The resolved InitialContext.

protected final String resolveUserTransactionName (Properties properties)

Given the lot of Hibernate configuration properties, resolve appropriate JNDI namespace to use for UserTransaction resolution.

We determine the namespace to use by

  1. Any specified jta.UserTransaction config property
  2. If a TransactionManagerLookup was indicated, use its getUserTransactionName()
  3. finally, as a last resort, we use DEFAULT_USER_TRANSACTION_NAME

Parameters
properties The Hibernate config properties.
Returns
  • The resolved UserTransaction namespace