1

For a simple test of functionality (following a tutorial) I try to setup a primitive JTA environment with Bitronix and H2 in-memory database. The test is supposed to run as Unit Test in a simple Java Application (no Java EE, no Server, etc.)

Unfortunately I don't get it to run, here's my setup:

  1. I added some jars (via maven) following the tutorial:

    • btm, h2, hibernate-entitymanager and hibernate-jpa-2.0-api
  2. I added persistence.xml, hibernate.cfg.xml and a jndi.properties file to the classpath.

  3. In the Test Method (dirty...) I put this code:

    PoolingDataSource ds = new PoolingDataSource();
    ds.setUniqueName( "jdbc/BitronixJTADataSource" );
    ds.setClassName( "org.h2.jdbcx.JdbcDataSource" );
    ds.setMaxPoolSize( 3 );
    ds.setAllowLocalTransactions( true );
    ds.getDriverProperties().put( "user", "sa" );
    ds.getDriverProperties().put( "password", "sasa" );
    ds.getDriverProperties().put( "URL", "jdbc:h2:mem:mydb" );
    ds.init();
    
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.persistence.jpa");
    

And this is my persistence.xml config:

<persistence-unit name="org.persistence.jpa" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/BitronixJTADataSource</jta-data-source>
    <class>org.drools.persistence.info.SessionInfo</class>
    <class>org.drools.persistence.info.WorkItemInfo</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
        <property name="hibernate.max_fetch_depth" value="3" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/> 
        <property name="hibernate.transaction.manager_lookup_class"
            value="org.hibernate.transaction.BTMTransactionManagerLookup" />
    </properties>
</persistence-unit>

And the jndi.properties: java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory

Problem is: I get this stack:

javax.persistence.PersistenceException: [PersistenceUnit: org.drools.persistence.jpa] Unable to build EntityManagerFactory
[...]
Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [jdbc/BitronixJTADataSource]
[...]
Caused by: javax.naming.OperationNotSupportedException
[...]

So certainly something's wrong here. Can you help me?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Alex
  • 1,141
  • 1
  • 13
  • 24

2 Answers2

1

I could solve this by using Hibernate 3.x instead of 4.x -> something must have changed but I did not investigate any further.

Alex
  • 1,141
  • 1
  • 13
  • 24
-1

"I could solve this by using Hibernate 3.x instead of 4.x -> something must have changed but I did not investigate any further."

By "could" do you mean "I think" or do you mean that you got it to work with Hibernate 3.x?