Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7FEE410213 for ; Fri, 16 Jan 2015 11:03:33 +0000 (UTC) Received: (qmail 42773 invoked by uid 500); 16 Jan 2015 11:03:35 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 42738 invoked by uid 500); 16 Jan 2015 11:03:35 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 42727 invoked by uid 99); 16 Jan 2015 11:03:35 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Jan 2015 11:03:35 +0000 Date: Fri, 16 Jan 2015 11:03:35 +0000 (UTC) From: "Grzegorz Grzybek (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (CAMEL-7269) camel-jpa - joinTransaction called for RESOURCE_LOCAL datasource MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-7269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14280049#comment-14280049 ] Grzegorz Grzybek edited comment on CAMEL-7269 at 1/16/15 11:03 AM: ------------------------------------------------------------------- camel-jpa uses spring-orm (for camel 2.12.0 it is spring-orm-3.2.4.RELEASE). Even if JpaConsumer (and JpaProducer) calls {{javax.persistence.EntityManager#joinTransaction()}}, the invocation is intercepted by spring-orm's {{org.springframework.orm.jpa.ExtendedEntityManagerCreator.ExtendedEntityManagerInvocationHandler#doJoinTransaction()}} method which delegates only if JTA is in use. So for {{transaction-type="RESOURCE_LOCAL"}} the call is not delegated. Here's working example: h6. META-INF/persistence.xml {code:xml} grgr.test.camel.model.Person true {code} h6. JUnit test {code:java} public class JpaTest extends CamelTestSupport { public static Logger LOG = LoggerFactory.getLogger(JpaTest.class); public static DateFormat TS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private javax.sql.DataSource ds; private EntityManagerFactory emf; @Override protected CamelContext createCamelContext() throws Exception { DataSource dataSource = new DataSource(); this.ds = dataSource; dataSource.setDriverClassName(Driver.class.getName()); // docker PostgreSQL instance dataSource.setUrl("jdbc:postgresql://172.17.0.2:5432/fuse?ApplicationName=QM"); dataSource.setUsername("postgres"); dataSource.setPassword("fuse"); LocalEntityManagerFactoryBean localEntityManagerFactoryBean = new LocalEntityManagerFactoryBean(); localEntityManagerFactoryBean.setJpaDialect(new OpenJpaDialect()); localEntityManagerFactoryBean.setPersistenceUnitName("camel"); HashMap jpaProperties = new HashMap<>(); jpaProperties.put("openjpa.ConnectionFactory", this.ds); localEntityManagerFactoryBean.setJpaPropertyMap(jpaProperties); localEntityManagerFactoryBean.afterPropertiesSet(); this.emf = localEntityManagerFactoryBean.getObject(); JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setDataSource(this.ds); txManager.setEntityManagerFactory(this.emf); txManager.afterPropertiesSet(); DefaultCamelContext context = (DefaultCamelContext) super.createCamelContext(); SimpleRegistry registry = new SimpleRegistry(); registry.put("txManager", txManager); context.setRegistry(registry); JpaComponent jpaComponent = new JpaComponent(); jpaComponent.setEntityManagerFactory(this.emf); jpaComponent.setTransactionManager(txManager); context.addComponent("jpa", jpaComponent); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .log("Body written: ${body}") .to("jpa:grgr.test.camel.model.Person"); from("jpa:grgr.test.camel.model.Person?consumeDelete=false&consumer.delay=5000") .transacted() .log("Body read: ${body}") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Person person = exchange.getIn().getBody(Person.class); LOG.info("Received: {} ({})", person.getName(), person.getDate()); } }); } }); return context; } @Test public void testJpaWrite() throws Exception { Person result = template.requestBody("direct:start", new Person("Terrence", new Date()), Person.class); LOG.info("Result: {}: {}", result.getId(), result.getName()); } } {code} Please reopen if the problem persists. was (Author: gzres): camel-jpa uses spring-orm (for camel 2.12.0 it is spring-orm-3.2.4.RELEASE). Even if JpaConsumer (and JpaProducer) calls {{javax.persistence.EntityManager#joinTransaction()}}, the invocation is intercepted by spring-orm's {{org.springframework.orm.jpa.ExtendedEntityManagerCreator.ExtendedEntityManagerInvocationHandler#doJoinTransaction()}} method which delegates only if JTA is in use. So for {{transaction-type="RESOURCE_LOCAL"}} the call is not delegated. Here's working example: h6. META-INF/persistence.xml {code:xml} grgr.test.camel.model.Person true {code} h6. JUnit test {code:java} public class JpaTest extends CamelTestSupport { public static Logger LOG = LoggerFactory.getLogger(JpaTest.class); public static DateFormat TS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private javax.sql.DataSource ds; private EntityManagerFactory emf; @Override protected CamelContext createCamelContext() throws Exception { DataSource dataSource = new DataSource(); this.ds = dataSource; dataSource.setDriverClassName(Driver.class.getName()); // docker PostgreSQL instance dataSource.setUrl("jdbc:postgresql://172.17.0.2:5432/fuse?ApplicationName=QM"); dataSource.setUsername("postgres"); dataSource.setPassword("fuse"); LocalEntityManagerFactoryBean localEntityManagerFactoryBean = new LocalEntityManagerFactoryBean(); localEntityManagerFactoryBean.setJpaDialect(new OpenJpaDialect()); localEntityManagerFactoryBean.setPersistenceUnitName("camel"); HashMap jpaProperties = new HashMap<>(); jpaProperties.put("openjpa.ConnectionFactory", this.ds); localEntityManagerFactoryBean.setJpaPropertyMap(jpaProperties); localEntityManagerFactoryBean.afterPropertiesSet(); this.emf = localEntityManagerFactoryBean.getObject(); JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setDataSource(this.ds); txManager.setEntityManagerFactory(this.emf); txManager.afterPropertiesSet(); DefaultCamelContext context = (DefaultCamelContext) super.createCamelContext(); SimpleRegistry registry = new SimpleRegistry(); registry.put("txManager", txManager); context.setRegistry(registry); JpaComponent jpaComponent = new JpaComponent(); jpaComponent.setEntityManagerFactory(this.emf); jpaComponent.setTransactionManager(txManager); context.addComponent("jpa", jpaComponent); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .transacted() .log("Body written: ${body}") .to("jpa:Person"); from("jpa:grgr.test.camel.model.Person?consumeDelete=false&consumer.delay=5000") .transacted() .log("Body read: ${body}") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Person person = exchange.getIn().getBody(Person.class); LOG.info("Received: {} ({})", person.getName(), person.getDate()); } }); } }); return context; } @Test public void testJpaWrite() throws Exception { Person result = template.requestBody("direct:start", new Person("Terrence", new Date()), Person.class); LOG.info("Result: {}: {}", result.getId(), result.getName()); } } {code} Please reopen if the problem persists. > camel-jpa - joinTransaction called for RESOURCE_LOCAL datasource > ---------------------------------------------------------------- > > Key: CAMEL-7269 > URL: https://issues.apache.org/jira/browse/CAMEL-7269 > Project: Camel > Issue Type: Bug > Components: camel-jpa > Affects Versions: 2.12.0 > Environment: tomcat+eclipselink+camel 2.12.2 > Reporter: Hristo Sabev > Assignee: Grzegorz Grzybek > Fix For: Future > > > At line 82, JpaConsumer calls entityManager.joinTransaction(). This call cannot really work in environmnent without JTA. This is a change since 2.11.x and earlier versions where non JTA environments were supported -- This message was sent by Atlassian JIRA (v6.3.4#6332)