8.2. Integrating with the Transaction Manager

Kodo EntityManagers and PersistenceManagers have the ability to automatically synchronize their transactions with an external transaction manager. Whether or not EntityManagers and PersistenceManagers 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:

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.


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:

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

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.


Skip navigation bar   Back to Top