8.2. Integrating with the Transaction Manager
Prev | Chapter 8. Deployment | Next

## 8.2. Integrating with the Transaction Manager

Kodo `EntityManager`s and `PersistenceManager`s have the ability to automatically synchronize their transactions with an external transaction manager. Whether or not `EntityManager`s and `PersistenceManager`s from a given factory exhibit this behavior by default depends on the `kodo.TransactionMode` configuration property. (Under JPA, Kodo translates the transaction type you set for the persistence unit in your `persistence.xml` file into a value for this property). The `kodo.TransactionMode` property accepts the following values:

- `local`: Perform transaction operations locally.

- `managed`: Integrate with the application server's managed global transactions.

You can override the global transaction mode setting when you obtain an `EntityManager` using the `EntityManagerFactory`'s `createEntityManager(Map props)` method by setting the `kodo.TransactionMode` key of the given `Map` to the desired value.

| Note
You can also override the `kodo.ConnectionUserName`, `kodo.ConnectionPassword`, and `kodo.ConnectionRetainMode` settings using the given `Map`.

You can override the global transaction mode setting when you obtain a `PersistenceManager` using the `KodoPersistenceManagerFactory`'s `getPersistenceManager(boolean managed, int connRetainMode)` method.

In order to use global transactions, Kodo must be able to access the application server's `javax.transaction.TransactionManager` . Kodo can automatically discover the transaction manager for most major application servers. Occasionally, however, you might have to point Kodo to the transaction manager for an unrecognized or non-standard application server setup. This is accomplished through the `kodo.ManagedRuntime` configuration property. This property describes a `kodo.ee.ManagedRuntime` implementation to use for transaction manager discovery. You can specify your own implementation, or use one of the built-ins:

- `auto`: This is the default. It is an alias for the `kodo.ee.AutomaticManagedRuntime` class. This managed runtime is able to automatically integrate with several common application servers.

- `invocation`: An alias for the `kodo.ee.InvocationManagedRuntime` class. You can configure this runtime to invoke any static method in order to obtain the appserver's transaction manager.

- `jndi`: An alias for the `kodo.ee.JNDIManagedRuntime` class. You can configure this runtime to look up the transaction manager at any JNDI location.

See the Javadoc for of each class for details on the bean properties you can pass to these plugins in your configuration string.

| Important
This feature requires Kodo Enterprise Edition.

Example 8.3. Configuring Transaction Manager Integration

JPA XML format:

    <property name="kodo.TransactionMode" value="managed"/>
    <property name="kodo.ManagedRuntime" value="jndi(TransactionManagerName=java:/TransactionManager)"/>

JDO properties format:

    kodo.TransactionMode: managed
    kodo.ManagedRuntime: jndi(TransactionManagerName=java:/TransactionManager)

Note that even when Kodo is using managed transaction, you can control transactions through the specification local transaction APIs if you wish. Kodo will propagate your transaction calls to the global transaction.

Prev | Up | Next
Chapter 8. Deployment | Home | 8.3. XA Transactions