Preloader image

Sample persistence.xml

For a unit called "movie-unit" using two datasources called "movieDatabase" and "movieDatabaseUnmanaged" the following persistence.xml would work.

<persistence version="1.0"

  <persistence-unit name="movie-unit">

      <property name="" value="create-drop"/>
      <property name="hibernate.transaction.manager_lookup_class"

Note that as of OpenEJB 3.1 you do not need to set the hibernate.transaction.manager_lookup_class as it will be set for you automatically and will overwrite any "org.hibernate.transaction." strategy class already set while leaving any custom strategy class you may have implemented untouched.

The result is that you can leave your hibernate.transaction.manager_lookup_class property configured to your production environment and OpenEJB will update it just for the scope testing. On the other hand if you have implemented a custom org.hibernate.transaction.TransactionManagerLookup strategy it will always be used and never replaced by OpenEJB.

Note that if you need more functionality in this area we are always happy to add it.

Not using OpenEJB in production?

If you’re using OpenEJB 3.0 which does not support the dynamic switching of the hibernate.transaction.manager_lookup_class this is one way to achieve it.

A custom implementation of Hibernate’s TransactionManagerLookup strategy like the following will do the trick. This "DynamicTransactionManagerLookup" class can be packed in your jar and deployed with your app.

import org.hibernate.HibernateException;
import org.hibernate.transaction.TransactionManagerLookup;
import jakarta.transaction.TransactionManager;
import java.util.Properties;

public class DynamicTransactionManagerLookup implements TransactionManagerLookup {

    private TransactionManagerLookup impl;

    public DynamicTransactionManagerLookup() {
        String[] strategies = {

        for (String className : strategies) {
            try {
                Class<?> clazz = this.getClass().getClassLoader().loadClass(className);
                impl = (TransactionManagerLookup) clazz.newInstance();
            } catch (Exception e) {

        if (impl == null) throw new IllegalStateException("No TransactionManagerLookup available");

    public TransactionManager getTransactionManager(Properties properties) throws HibernateException {
        return impl.getTransactionManager(properties);

    public String getUserTransactionName() {
        return impl.getUserTransactionName();

Then set the Hibernate specific configuration property hibernate.transaction.manager_lookup_class to the name of the factory that you just created.