Hi,
I have the following setup. We are using Tomcat as the container. JPA is used to manage our entities, Hibernate is the JPA provider. We also use Infinispan as the L2C. On top of this everything is running within Spring.
We have a spring-hibernate.xml file that is defined as:
We also have the following persistence.xml fileCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schem...ng-jee-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schem...g-lang-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schem...g-util-3.0.xsd"> <!-- use annotations for transaction management --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- Process the PersistenceUnit and PersistenceContext annotations --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <!-- spring's simple connection data source --> <bean id="dataSource.hsqldb" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true" scope="singleton"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="${datasource.url}" /> <property name="username" value="" /> <property name="password" value="" /> </bean> <!-- application datasource --> <bean id="dataSource.jndi" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton"> <property name="jndiName" value="java:comp/env/jdbc/ds" /> </bean> <!-- official dataSource --> <alias alias="dataSource" name="${data.source.id}" /> <!-- Transaction Manager --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="dataSource" ref="dataSource" /> </bean> <!-- Transaction Template --> <bean id="org.springframework.transaction.support.TransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate" > <property name="transactionManager" ref="transactionManager"/> </bean> <!-- Hibernate/JPA configuration --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="jpa" /> <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /> <property name="dataSource" ref="dataSource" /> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> </property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="false" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="${hibernate.dialect}" /> </bean> </property> </bean> </beans>
I need to configure Infinispan to use the same transaction manager as JPA (Hibernate). I am stumbling upon the fact that we have defined a jpa transaction but I can't see how I can retrieve the JTA from it. On the other side if I define the JTA transaction how do I tell it to use the entity manager?Code:<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="jpa"> <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> <properties> <property name="hibernate.cache.infinispan.cfg" value="infinispan-config.xml"/> <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/> <property name="hibernate.cache.infinispan.cachemanager" value="java:CacheManager/entity" /> <property name="hibernate.cache.infinispan.use_synchronization" value="true"/> <property name="hibernate.cache.infinispan.statistics" value="true" /> <property name="hibernate.cache.use_second_level_cache" value="true" /> <property name="hibernate.cache.use_query_cache" value="true" /> <property name="hibernate.generate_statistics" value="true" /> <property name="hibernate.cache.use_structured_entries" value="true" /> </properties> </persistence-unit> </persistence>
I understand that I could also specify a transaction manager lookup class in the persistence xml such as:
But since I am using Tomcat I have to somehow wire it via JNDI according to this documentation:Code:<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
https://docs.jboss.org/author/displa...Cache+Provider
I am bit lost could anyone point me to the right direction?
Thank you.


Reply With Quote
