Top Description Fields Constructors Methods
org.hibernate.transaction

public Class JTATransactionFactory

extends Object
implements TransactionFactory
Class Inheritance
All Implemented Interfaces
org.hibernate.transaction.TransactionFactory
Imports
java.util.Properties, javax.naming.InitialContext, .NamingException, javax.transaction.SystemException, .UserTransaction, org.slf4j.Logger, .LoggerFactory, org.hibernate.ConnectionReleaseMode, .HibernateException, .Transaction, .TransactionException, org.hibernate.jdbc.JDBCContext, org.hibernate.cfg.Environment, org.hibernate.util.NamingHelper, .JTAHelper

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. Hibernate will then attempt to locate the UserTransaction within this resolved InitialContext based on the namespace returned by resolveUserTransactionName.

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.

Authors
Gavin King, Steve Ebersole, Les Hazlewood

Field Summary

Modifier and TypeField and Description
public static final String
protected InitialContext
private static final Logger
protected String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
configure(Properties
The configuration properties
props
)

Implements org.hibernate.transaction.TransactionFactory.configure.

Configure this transaction factory.
public Transaction
createTransaction(JDBCContext
The jdbc context to which the transaction belongs
jdbcContext
,
TransactionFactory.Context
The contract regarding the context in which this transaction will operate.
transactionContext
)

Implements org.hibernate.transaction.TransactionFactory.createTransaction.

Begin a transaction and return the associated Transaction instance.
public ConnectionReleaseMode
protected InitialContext

Returns:

Value for property 'initialContext'.
getInitialContext
()

Getter for property 'initialContext'.

protected UserTransaction

Returns:

The appropriate UserTransaction reference.
getUserTransaction
()

Get the UserTransaction reference.

protected String

Returns:

Value for property 'userTransactionName'.
getUserTransactionName
()

Getter for property 'userTransactionName'.

public boolean
isTransactionInProgress(JDBCContext
The JDBC context
jdbcContext
,
TransactionFactory.Context
The transaction context
transactionContext
,
Transaction
The Hibernate transaction
transaction
)

Implements org.hibernate.transaction.TransactionFactory.isTransactionInProgress.

Determine whether an underlying transaction is in progress.
public boolean
isTransactionManagerRequired()

Implements org.hibernate.transaction.TransactionFactory.isTransactionManagerRequired.

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

Returns:

The resolved InitialContext.
resolveInitialContext
(Properties
The Hibernate config properties.
properties
)

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

protected final String

Returns:

The resolved UserTransaction namespace
resolveUserTransactionName
(Properties
The Hibernate config properties.
properties
)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_USER_TRANSACTION_NAMEback to summary
public static final String DEFAULT_USER_TRANSACTION_NAME
initialContextback to summary
protected InitialContext initialContext
logback to summary
private static final Logger log
userTransactionNameback to summary
protected String userTransactionName

Constructor Detail

JTATransactionFactoryback to summary
public JTATransactionFactory()

Method Detail

areCallbacksLocalToHibernateTransactionsback to summary
public boolean areCallbacksLocalToHibernateTransactions()

Implements org.hibernate.transaction.TransactionFactory.areCallbacksLocalToHibernateTransactions.

Doc from org.hibernate.transaction.TransactionFactory.areCallbacksLocalToHibernateTransactions.

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

Returns:boolean

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

configureback to summary
public void configure(Properties props) throws HibernateException

Implements org.hibernate.transaction.TransactionFactory.configure.

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:Properties

The configuration properties

Exceptions
HibernateException:

Doc from org.hibernate.transaction.TransactionFactory.configure.

Indicates a problem configuring this factory.

createTransactionback to summary
public Transaction createTransaction(JDBCContext jdbcContext, TransactionFactory.Context transactionContext) throws HibernateException

Implements org.hibernate.transaction.TransactionFactory.createTransaction.

Doc from org.hibernate.transaction.TransactionFactory.createTransaction.

Begin a transaction and return the associated Transaction instance.

Parameters
jdbcContext:JDBCContext

The jdbc context to which the transaction belongs

transactionContext:TransactionFactory.Context

The contract regarding the context in which this transaction will operate.

Returns:Transaction

Transaction

Exceptions
HibernateException:
Indicates a problem generating a transaction instance
getDefaultReleaseModeback to summary
public ConnectionReleaseMode getDefaultReleaseMode()

Implements org.hibernate.transaction.TransactionFactory.getDefaultReleaseMode.

Doc from org.hibernate.transaction.TransactionFactory.getDefaultReleaseMode.

Get the default connection release mode.

Returns:ConnectionReleaseMode

The default release mode associated with this strategy

getInitialContextback to summary
protected InitialContext getInitialContext()

Getter for property 'initialContext'.

Returns:InitialContext

Value for property 'initialContext'.

getUserTransactionback to summary
protected UserTransaction getUserTransaction()

Get the UserTransaction reference.

Returns:UserTransaction

The appropriate UserTransaction reference.

getUserTransactionNameback to summary
protected String getUserTransactionName()

Getter for property 'userTransactionName'. The algorithm here is

Returns:String

Value for property 'userTransactionName'.

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

Implements org.hibernate.transaction.TransactionFactory.isTransactionInProgress.

Doc from org.hibernate.transaction.TransactionFactory.isTransactionInProgress.

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:JDBCContext

The JDBC context

transactionContext:TransactionFactory.Context

The transaction context

transaction:Transaction

The Hibernate transaction

Returns:boolean

true if an underlying transaction is know to be in effect.

isTransactionManagerRequiredback to summary
public boolean isTransactionManagerRequired()

Implements org.hibernate.transaction.TransactionFactory.isTransactionManagerRequired.

Doc from org.hibernate.transaction.TransactionFactory.isTransactionManagerRequired.

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

Returns:boolean

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

resolveInitialContextback to summary
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:Properties

The Hibernate config properties.

Returns:InitialContext

The resolved InitialContext.

resolveUserTransactionNameback to summary
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 TransactionManagerLookup#getUserTransactionName
  3. finally, as a last resort, we use DEFAULT_USER_TRANSACTION_NAME
Parameters
properties:Properties

The Hibernate config properties.

Returns:String

The resolved UserTransaction namespace