I am trying to create transaction manager and use it with Hibernate for Oracle.
My persistence.xml file is:
<persistence-unit name="org.drools.persistence.jpa"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/testDS1</jta-data-source>
<class>org.drools.persistence.session.SessionInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.processinstance.WorkItemInfo</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup" />
</properties>
</persistence-unit>
In applicationContext.xml of spring I added:
<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close">
<property name="className" value="oracle.jdbc.xa.client.OracleXADataSource" />
<property name="uniqueName" value="jdbc/testDS1" />
<property name="minPoolSize" value="1" />
<property name="maxPoolSize" value="5" />
<property name="driverProperties">
<props>
<prop key="URL">myURL</prop>
<prop key="user">username</prop>
<prop key="password">password</prop>
</props>
</property>
</bean>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="bitronixTransactionManager"/>
<property name="userTransaction" ref="bitronixTransactionManager"/>
</bean>
<bean id="bitronixTransactionManager" factory-method="getTransactionManager"
class="bitronix.tm.TransactionManagerServices" depends-on="dataSource,txManager"
destroy-method="shutdown"/>
However, when I run:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
I get an exception:
Caused by: org.hibernate.HibernateException: Could not find datasource: jdbc/testDS1
The exception is on ds = (DataSource ) NamingHelper.getInitialContext(props).lookup(jndiName); of Hibernate infra file.
-
What could be the problem?
-
How does Hibernate persistence knows to refer to spring
txManagerbean?
Your persistence provider does its lookups on jndi. Data sources defined in Spring application context are not bound to jndi. Hence, persistence provider’s lookup attempt for the data source fails as there is no such data source bound to jndi.
You may want to check http://forum.springsource.org/showthread.php?t=13984.
Can you try defining your data sources in the server context and looking them up in your spring application by their jndi names?