EhCache CacheManager with multiple EntityManagerFactory - spring

And one entityManagerFactory in spring-server.xml.
But i must generate one more entityManager, and i do it with
Persistence.createEntityManagerFactory("myotherpersistenceunitname");
but i get exception
Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ]
at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:457)
at net.sf.ehcache.CacheManager.init(CacheManager.java:354)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:242)
at net.sf.ehcache.hibernate.EhCacheRegionFactory.start(EhCacheRegionFactory.java:70)
spring.xml:
<context:property-placeholder location="classpath:application.properties"/>
<context:component-scan base-package="merve.web.app" >
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan>
<context:annotation-config/>
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true" />
<cache:annotation-driven />
<bean id="properties" class="merve.web.app.configuration.PropertyResourceConfiguration" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myPU"/>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="${database.target}"/>
<property name="showSql" value="${database.showSql}" />
</bean>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${database.driver}"/>
<property name="jdbcUrl" value="${database.url}"/>
<property name="user" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="minPoolSize" value="2"/>
<property name="maxPoolSize" value="10"/>
<property name="breakAfterAcquireFailure" value="false"/>
<property name="acquireRetryAttempts" value="3"/>
<property name="idleConnectionTestPeriod" value="300" />
<property name="testConnectionOnCheckout" value="true" />
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jamesEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="jamesPU"/>
<property name="dataSource" ref="dataSourceJames" />
<property name="persistenceXmlLocation" value="classpath:META-INF/james-persistence.xml"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="dataSourceJames" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="jdbcUrl" value="jdbc:derby:../var/store/derby;create=true"/>
<property name="user" value="app"/>
<property name="password" value="app"/>
<property name="minPoolSize" value="2"/>
<property name="maxPoolSize" value="10"/>
<property name="breakAfterAcquireFailure" value="false"/>
<property name="acquireRetryAttempts" value="3"/>
<property name="idleConnectionTestPeriod" value="300" />
<property name="testConnectionOnCheckout" value="true" />
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
<!-- Ehcache library setup -->
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:shared="true" p:config-location="classpath:ehcache.xml"/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" >
<property name="cacheManager"><ref local="ehcache"></ref></property>
</bean>
<dwr:configuration/>
<dwr:annotation-scan base-package="tuxi.web.app.service.dwr" scanRemoteProxy="true" scanDataTransferObject="true"/>
<dwr:url-mapping />
<dwr:controller id="dwrController"/>
</beans>

The problem, described here, and fixed in the source is not using the EhCache singleton correctly. The answer depends on which version of spring-context-support AND which version of EhCache you are using. For both, you need to be using EhCache 2.6 or greater:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.6.0</version>
</dependency>
Next, determine what to do based on your spring-context-support version:
If using Spring 3.1/3.2
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:shared="true"
p:config-location="classpath:ehcache.xml"/>
If using Spring 4.x
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:shared="false"
P:acceptExisting="true"
p:config-location="classpath:ehcache.xml"/>

Try naming both cacheManagers differently in ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="ehCacheManager1">
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="ehCacheManager2">

Related

Not able to ref dataSource from other bean configuartion in Spring

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="${models.DS_POOL_NAME}" />
</property>
</bean>
<bean id="DBPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="properties">
<bean class="org.apache.commons.configuration2.ConfigurationConverter" factory-method="getProperties">
<constructor-arg>
<bean id="DatabaseConfigurator" class="org.apache.commons.configuration2.DatabaseConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="table" value="sample" />
<property name="keyColumn" value="PROPERTY" />
<property name="valueColumn" value="VALUE" />
<property name="configurationNameColumn" value="GROUP_NAME" />
<property name="configurationName" value="new" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
when we ref dataSource in DBPlaceholder bean then ${models.DS_POOL_NAME} will showing error because this value is coming from properties

Error at Server Startup while adding ActiveMQ by replacing HornetQ

I am using Spring 4, Hibernate, and ActiveMQ using REST APIs
ActiveMQ configurations
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="connectionFactory"></property>
</bean>
<!-- Configuration for Publishing Jms Messages -->
<bean id="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="disableTimeStampsByDefault" value="true"/>
<property name="useAsyncSend" value="true"/>
<property name="nonBlockingRedelivery" value="true"/>
<property name="redeliveryPolicy" ref="redeliveryPolicy"/>
</bean>
<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
<property name="initialRedeliveryDelay" value="60000"/>
<property name="backOffMultiplier" value="3"/>
<property name="maximumRedeliveryDelay" value="60000"/>
<property name="maximumRedeliveries" value="3"/>
<property name="redeliveryDelay" value="60000"/>
<property name="useExponentialBackOff" value="true"/>
</bean>
<!--<bean id="outgoingSmsQueue" class="org.apache.activemq.command.ActiveMQQueue">
<property name="physicalName" value="queue/outgoingSmsQueue"/>
</bean>
<bean id="emailServiceQueue" class="org.apache.activemq.command.ActiveMQQueue">
<property name="physicalName" value="queue/emailServiceQueue"/>
</bean>-->
<bean id="activemqOrderQueue" class="org.apache.activemq.command.ActiveMQQueue">
<property name="physicalName" value="ActiveMQ.orderQueue"/>
</bean>
<bean id="activemqDLQ" class="org.apache.activemq.command.ActiveMQQueue">
<property name="physicalName" value="ActiveMQ.DLQ"/>
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="activeMqConnectionFactory"/>
<property name="sessionCacheSize" value="200"/>
<property name="cacheProducers" value="true"/>
<property name="cacheConsumers" value="true"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="sessionTransacted" value="true"/>
<property name="deliveryPersistent" value="true"/>
<property name="explicitQosEnabled" value="true"/>
<property name="messageIdEnabled" value="false"/>
<property name="messageTimestampEnabled" value="false"/>
</bean>
<bean id="jmsProducer" class="com.mahopos.jms.JmsProducerImpl">
<property name="jmsTemplate" ref="jmsTemplate"/>
</bean>
<!-- End Configuration for Publishing Jms Messages -->
<bean id="dlqMessageListener" class="com.mahopos.jms.DlqMessageListener" autowire="byName">
</bean>
<bean id="dlqMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
parent="baseMessageListenerContainer">
<property name="destination" ref="activemqDLQ"/>
<property name="messageListener" ref="dlqMessageListener"/>
</bean>
<bean id="baseMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
abstract="true">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="transactionManager" ref="jmsTransactionManager"/>
<property name="concurrentConsumers" value="10"/>
<property name="maxConcurrentConsumers" value="10"/>
<property name="idleConsumerLimit" value="1"/>
<property name="receiveTimeout" value="5000"/>
<property name="idleTaskExecutionLimit" value="50"/>
<property name="cacheLevel">
<util:constant
static-field="org.springframework.jms.listener.DefaultMessageListenerContainer.CACHE_CONSUMER"/>
</property>
</bean>
<bean id="orderQueueListener" class="com.mahopos.jms.OrderQueueListener">
<property name="demoApiService" ref="demoApiService"/>
<property name="delay" value="1500"/>
</bean>
<bean id="orderQueueListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
parent="baseMessageListenerContainer">
<property name="concurrentConsumers" value="5"/>
<property name="destination" ref="activemqOrderQueue"/>
<property name="messageListener" ref="orderQueueListener"/>
<property name="sessionTransacted" value="true"/>
</bean>
Apparently it seems that either ContextLoaderListener is initialized more than one time, but where?
The server runs successfully but the attached image is shown in Chrome (browser) and no REST call is running after server startup.
#justin Bertram, HornetQ was working previously and I replaced it with Activemq, and the application is REST base.
Issue is resolved by adding replacing the dependency from
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
to
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.22.RELEASE</version>
</dependency>
it seems issue was due to conflicting libraries

Multiple datasource configuration issue

In my project I am using two oracle datasources for one of the datasource Im using LocalSessionFactoryBean and for another LocalContainerEntityManagerFactoryBean
I am mapping the datasources accordingly but when Im trying to get sessionFactory for LocalSessionFactoryBean the datasource details are that of the other. Dono what I am doing wrong.
<tx:annotation-driven transaction-manager="xxxTransactionManager" />
<bean id="xxxEntityManagerFactoryBean"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean class="org.modelmapper.ModelMapper" id="modelMapper"/>
<bean id="xxxEntityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="xxxEntityManagerFactoryBean" />
</bean>
<bean id="xxxTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="xxxEntityManagerFactoryBean" />
<property name="nestedTransactionAllowed" value="true" />
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
in another xml file that is imported i have
<bean id="sessionFactoryNew"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="packagesToScan" value="com.citi.aml.npa.domain.api" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
<bean id="xxxTransactionManagerNew"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryNew" />
<qualifier value="xxxtransaction"/>
</bean>
in app context.xml i have the datasources like
<beans profile="local">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db.oracle.driverClassName}" />
<property name="username" value="${db.oracle.username}" />
<property name="password" value="${db.oracle.password}" />
<property name="url" value="${db.oracle.url}" />
</bean>
<context:property-placeholder location="classpath*:/config/local/yyy.properties" ignore-unresolvable="true"/>
</beans>
<beans profile="local">
<bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db.oracle.driverClassName}" />
<property name="username" value="${db.oracle.username}" />
<property name="password" value="${db.oracle.password}" />
<property name="url" value="${db.oracle.url}" />
</bean>
<context:property-placeholder location="classpath*:/config/local/xxx_db.properties" ignore-unresolvable="true"/>
</beans>
in Dao impl calss i have
#Repository
public class OracledbTestRepository implements TestRepository {
#Autowired
#Qualifier(value = "sessionFactoryNew")
SessionFactory sessionFactory;
#SuppressWarnings("unchecked")
#Override
public List<xxx> getTestData() {
Session session = sessionFactory.getCurrentSession();
System.out.println(sessionFactory);
List<xxx> xxxTestDatas = session.createCriteria(xxx.class).list();
return xxxTestDatas;
}
}
any help will be appreciated.
Your bean configuration looks a bit wonky to me. You have two different profiles with the same name. If these two datasources need to run at the same time, it would be simpler to consolidate your database properties into a single file, and place both datasource configurations within the same profile element.
So, for the consolidated database.properties, do something like:
db1.oracle.url=jdbc:oracle:thin:#server1...
db1.oracle.username=foo
...
db2.oracle.url=jdbc:oracle:thin:#server2...
db2.oracle.username=bar
And for the bean config, use something like:
<beans profile="local">
<context:property-placeholder location="classpath*:/config/local/database.properties" ignore-unresolvable="true"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db1.oracle.driverClassName}" />
<property name="username" value="${db1.oracle.username}" />
<property name="password" value="${db1.oracle.password}" />
<property name="url" value="${db1.oracle.url}" />
</bean>
<bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${db2.oracle.driverClassName}" />
<property name="username" value="${db2.oracle.username}" />
<property name="password" value="${db2.oracle.password}" />
<property name="url" value="${db2.oracle.url}" />
</bean>
</beans>

How to create apache camel XA connection using JNDI in Atomikos

Hi i am trying to create a XA transaction for camel and jdbc using atomikos but i have JNDI to set up a XA jdbc transaction i am having issues configuring it.
Below is my code and i am getting cannot write to the class exception
<!-- Atomikos and Spring transaction configuration -->
<!-- JMS config; with XAConnectionFactory -->
<bean id="xa.amqConnectionFactory" class="org.apache.activemq.spring.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!-- nothing transactional here, this connection factory will be used from the test harness -->
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!-- Atomikos JTA configuration, nothing specific to Spring here -->
<bean id="atomikos.connectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="My_MQSeries_XA_RMI"/>
<property name="xaConnectionFactory" ref="xa.amqConnectionFactory"/>
<!-- XAConnectionFactory -->
<property name="maxPoolSize" value="10"/>
<property name="ignoreSessionTransactedFlag" value="false"/>
</bean>
<!-- database config; the XADataSource bean is both a DataSource and an XADataSource-->
<!-- <import resource="xa-embedded-db-context.xml"/> -->
<bean id="db2jndi" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value = "jndi NAMe"/>
</bean>
<!-- <bean id="XADataSource" class="MyDAOclass">
<property name="MyDAOmethod" ref="db2jndi"/>
</bean> -->
<bean id="atomikos.dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean">
<property name="xaDataSource" ref="XADataSource"/>
<!-- XADataSource -->
</bean>
<!-- javax.transaction.TransactionManager -->
<bean id="atomikos.transactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init"
destroy-method="close"
depends-on="atomikos.connectionFactory,atomikos.dataSource">
<property name="forceShutdown" value="false"/>
</bean>
<!-- javax.transaction.UserTransaction -->
<bean id="atomikos.userTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300"/>
</bean>
<!-- This is the Spring wrapper over the JTA configuration -->
<!-- org.springframework.transaction.PlatformTransactionManager -->
<bean id="jta.transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikos.transactionManager"/>
<property name="userTransaction" ref="atomikos.userTransaction"/>
</bean>
<!-- Camel components -->
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="atomikos.connectionFactory"/>
<property name="transactionManager" ref="jta.transactionManager"/>
</bean>
<!-- this component is used only from the test harness -->
<bean id="nonTxJms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="atomikos.dataSource"/>
</bean>
<!-- Policy -->
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="jta.transactionManager"/>
<!-- Atomikos TX Manager -->
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
If anyone has worked on apache camel using XA transactions can you guys provide me your sample config file so that i can use and modify it.
This works for me. It looks like you've missed the ActiveMQResourceManager. Also ensure you use a XAPooledConnectionFactory otherwise your MDBs will disconnect after every bind to check for a message (and CPU on the broker will go through the roof).
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<bean id="env" class="java.lang.String">
<constructor-arg value="test-junit"/>
</bean>
<!-- JMS configuration -->
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager"
init-method="recoverResource">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="connectionFactory" ref="pooledJmsXaConnectionFactory" />
<property name="resourceName" value="activemq.default" />
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="userTransaction" />
</bean>
<bean id="pooledJmsXaConnectionFactory" class="org.apache.activemq.pool.XaPooledConnectionFactory"
init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="jmsXaConnectionFactory" />
<property name="transactionManager" ref="atomikosTransactionManager" />
</bean>
<!-- <bean id="pooledJmsXaConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close"> <property name="poolSize" value="8"
/> <property name="uniqueResourceName" value="activemq" /> <property name="xaConnectionFactory"
ref="jmsXaConnectionFactory" /> </bean> -->
<bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="0" />
</bean>
</property>
</bean>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="pooledJmsXaConnectionFactory" />
<property name="transacted" value="false" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<!-- JMS configuration for test enqueue/dequeue without transactions -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="myEmf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="persistenceXmlLocation" value="classpath:META-INF/test-persistence.xml"/>
</bean>
<!-- JDBC configuration -->
<bean id="dataSource" class="org.apache.commons.dbcp2.managed.BasicManagedDataSource">
<property name="transactionManager" ref="atomikosTransactionManager" />
<!-- <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedXADataSource40" /> -->
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url" value="jdbc:derby:target/testdb;create=true" />
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean id="userTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="120" />
</bean>
<!-- -->
<bean id="springContext" class="org.example.testutils.SpringContext"/>
</beans>

Camel Transaction Configuration Issue: javax.persistence.TransactionRequiredException

I'm configuring JMS Transactions in Camel 2.10.4 routes. When I run my app, a javax.persistence.TransactionRequiredException: no transaction in progress is thrown. From my research, I found out that this exception is thrown when no method is marked #Transactional. The relevant sections in my application context XML config file is shown:
<bean id="txMgr" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="pooledConnectionFactory" />
</bean>
<bean id="REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="txMgr" />
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" />
</bean>
<bean id="pooledConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="transacted" value="true" />
<property name="transactionManager" ref="txMgr" />
<property name="concurrentConsumers" value="3"/>
</bean>
Besides the JMS-specific configuration, I also have JPA configuration, which is shown below:
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager">
<bean class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</property>
</bean>
<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="fileRecord" />
</bean>
If I disable transactions, the configuration works. When I enable it, however, all the other steps succeeds except the bit where the data is to be inserted into the database (at the JPA endpoint).
Any suggestions on what I need to change or add will be appreciated very much.

Resources