You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sriraman Gopalan <sr...@gmail.com> on 2012/06/21 09:35:36 UTC

Problem with Camel Jpa Component and Container Managed Transaction

Dear All,

I have a camel route that polls the database (using a jpa consumer) as shown
below:

Camel Route:

=================================================================
from("jpa:samples.CustomerAccount?consumer.namedQuery=selectAllCustomerAccounts&consumeDelete=false")
.to("log:test-out")

My persistence.xml is as follows:
=================================================================
<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="pdsprint1" transaction-type="JTA">
    
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
       
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/pdsprint1)</jta-data-source>
        
        <class>samples.CustomerAccount</class>
        <class>samples.AccountInfo</class>
        
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        
        <properties>
            <property name="openjpa.ConnectionFactoryMode" value="managed"/>
            <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
            <property name="openjpa.jdbc.DBDictionary"
value="org.apache.openjpa.jdbc.sql.H2Dictionary"/>
            <property name="openjpa.ManagedRuntime"
value="jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager)"/>
            <property name="openjpa.Log" value="DefaultLevel=TRACE,
Tool=INFO" />
        </properties>
    </persistence-unit>

</persistence>

================================================================

My blueprint configuration is as follows:

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
		<tx:transaction method="*" />
		<property name="entityManagerFactory" ref="entityManagerFactory" />
		<property name="transactionManager" ref="transactionManager" />
</bean>
	
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<reference id="entityManagerFactory"
interface="javax.persistence.EntityManagerFactory"
filter="(osgi.unit.name=pdsprint1)" />

=================================================================

However, I am getting the following error when I start the bundle:

Consumer[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000&consumer.namedQuery=selectAllCustomerAccounts]
could not poll endpoint:
Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000&consumer.namedQuery=selectAllCustomerAccounts]
caused by: Could not open JPA EntityManager for transaction; nested
exception is <openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.
org.springframework.transaction.CannotCreateTransactionException: Could not
open JPA EntityManager for transaction; nested exception is
<openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.

Note:

I have the following features installed in Karaf:

1. jpa
2. jndi
3. transaction
4. camel-jpa

Also, my data source is configured via another bundle as shown below as
suggested by  
Christian Schneider in his blog 

http://www.liquid-reality.de/display/liquid/2012/01

=================================================================

<cm:property-placeholder persistent-id="samples.datasource">
	</cm:property-placeholder>

	<bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
		<property name="URL" value="${db.url}" />
		<property name="user" value="${db.userid}" />
		<property name="password" value="${db.password}" />
	</bean>

	<service interface="javax.sql.DataSource" ref="dataSource">
		<service-properties>
			<entry key="osgi.jndi.service.name" value="jdbc/pdsprint1" />
		</service-properties>
	</service>

=================================================================
Can somebody point me in the right direction?

best regards
Sriraman.


--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by doxumd <do...@yahoo.com>.
I need your help, I'm using pretty much the same example with a RouteTest
class and it does not work as expected because of the following line :

Bundle RouteTest is waiting for namespace handlers
[http://aries.apache.org/xmlns/jpa/v1.1.0]






--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5730256.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

The problem you're facing is pretty obvious: Looking at your persistence.xml
you do ask for a "Container managed global transaction", as you have defined
the transaction type to be "JTA", as well you've defined a
JTA-enabled-Datasource for it. BUT you make use of spring
JpaTransactionManager which doesn't match to this requirment (provides only
local transactions for one single resource)! Look at the source of
JpaTransactionManager to see how it manages the transactions
(commit/rollback). And this's exactly why OpenJPA barks on your box :-)

So to be consistent either make use of spring JtaTransactionManager instead
of JpaTransactionManager (providing global transaction demarcation), but
then there should be a JTA-TM running inside your container (e.g. Arjuna,
Atomikos, etc.) talking to spring JtaTransactionManager.

The other option could be to stick to "local transactions", that's:

<persistence-unit name="pdsprint1" transaction-type="RESOURCE_LOCAL">

And removing the JTA-Datasource inside persistence.xml.

Looking at your Camel route I would go for the second option as database is
the *only* transactional resource you have, e.g. you don't need any
orchestration between a JPA-Resource together with a JMS-Resource.

Babak 


--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5714928.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by Sriraman Gopalan <sr...@gmail.com>.
Hi Claus,

Thanks for the suggestion. I don't have a test case offhand which I can
share with you right away. I will work on this and will share the same once
it is ready.

best regards
Sriraman.

--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5714923.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You run this in OSGi Blueprint.

Just to be sure, have you got this running outside osgi in lets say a
regular junit test case or something.
This helps track down knowing its related to your runtime platform.



On Fri, Jun 22, 2012 at 8:56 AM, Sriraman Gopalan <sr...@gmail.com> wrote:
> Hi Claus,
>
> Thanks for the quick reply.
>
> Please find below the complete log from the point the consumer poll is
> started till it is completed:
>
> 2012-06-22 12:11:20,178 | TRACE | .CustomerAccount | ScheduledPollConsumer
> | 84 - org.apache.camel.camel-core - 2.9.2 | Scheduled task started on:
> Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
> 2012-06-22 12:11:20,179 | TRACE | .CustomerAccount | ScheduledPollConsumer
> | 84 - org.apache.camel.camel-core - 2.9.2 | Starting to poll:
> Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
> 2012-06-22 12:11:20,179 | DEBUG | .CustomerAccount | JpaTransactionManager
> | 77 - org.springframework.transaction - 3.0.7.RELEASE | Creating new
> transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
> 2012-06-22 12:11:20,180 | DEBUG | .CustomerAccount | JpaTransactionManager
> | 77 - org.springframework.transaction - 3.0.7.RELEASE | Opened new
> EntityManager
> [org.apache.aries.jpa.container.impl.EntityManagerWrapper@3192caa9] for JPA
> transaction
> 2012-06-22 12:11:20,180 | DEBUG | .CustomerAccount | JpaTransactionManager
> | 77 - org.springframework.transaction - 3.0.7.RELEASE | Could not rollback
> EntityManager after failed transaction begin
> <openjpa-2.1.1-r422266:1148538 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: You cannot access the
> EntityTransaction when using managed transactions.
>        at
> org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:551)[176:org.apache.openjpa:2.1.1]
>        at
> org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:101)[176:org.apache.openjpa:2.1.1]
>        at
> org.apache.aries.jpa.container.impl.EntityManagerWrapper.getTransaction(EntityManagerWrapper.java:153)[54:org.apache.aries.jpa.container:0.3.0]
>        at
> org.springframework.orm.jpa.JpaTransactionManager.closeEntityManagerAfterFailedBegin(JpaTransactionManager.java:412)[170:org.springframework.orm:3.0.7.RELEASE]
>        at
> org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:381)[170:org.springframework.orm:3.0.7.RELEASE]
>        at
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)[77:org.springframework.transaction:3.0.7.RELEASE]
>        at
> org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)[77:org.springframework.transaction:3.0.7.RELEASE]
>        at
> org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[177:org.apache.camel.camel-jpa:2.9.2]
>        at
> org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:81)[177:org.apache.camel.camel-jpa:2.9.2]
>        at
> org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138)[84:org.apache.camel.camel-core:2.9.2]
>        at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90)[84:org.apache.camel.camel-core:2.9.2]
>        at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_29]
>        at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_29]
>        at
> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_29]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_29]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_29]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_29]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
>        at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
> 2012-06-22 12:11:20,180 | DEBUG | .CustomerAccount |
> EntityManagerFactoryUtils        | 170 - org.springframework.orm -
> 3.0.7.RELEASE | Closing JPA EntityManager
> 2012-06-22 12:11:20,183 | WARN  | .CustomerAccount |
> faultPollingConsumerPollStrategy | 84 - org.apache.camel.camel-core - 2.9.2
> | Consumer
> Consumer[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
> could not poll endpoint:
> Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
> caused by: Could not open JPA EntityManager for transaction; nested
> exception is <openjpa-2.1.1-r422266:1148538 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: You cannot access the
> EntityTransaction when using managed transactions.
> org.springframework.transaction.CannotCreateTransactionException: Could not
> open JPA EntityManager for transaction; nested exception is
> <openjpa-2.1.1-r422266:1148538 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: You cannot access the
> EntityTransaction when using managed transactions.
>        at
> org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:382)[170:org.springframework.orm:3.0.7.RELEASE]
>        at
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)[77:org.springframework.transaction:3.0.7.RELEASE]
>        at
> org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)[77:org.springframework.transaction:3.0.7.RELEASE]
>        at
> org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[177:org.apache.camel.camel-jpa:2.9.2]
>        at
> org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:81)[177:org.apache.camel.camel-jpa:2.9.2]
>        at
> org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138)[84:org.apache.camel.camel-core:2.9.2]
>        at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90)[84:org.apache.camel.camel-core:2.9.2]
>        at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_29]
>        at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_29]
>        at
> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_29]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_29]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_29]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_29]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
>        at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
> Caused by: <openjpa-2.1.1-r422266:1148538 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: You cannot access the
> EntityTransaction when using managed transactions.
>        at
> org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:551)[176:org.apache.openjpa:2.1.1]
>        at
> org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:101)[176:org.apache.openjpa:2.1.1]
>        at
> org.apache.aries.jpa.container.impl.EntityManagerWrapper.getTransaction(EntityManagerWrapper.java:153)[54:org.apache.aries.jpa.container:0.3.0]
>        at
> org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)[170:org.springframework.orm:3.0.7.RELEASE]
>        at
> org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:332)[170:org.springframework.orm:3.0.7.RELEASE]
>        ... 15 more
> 2012-06-22 12:11:20,185 | TRACE | .CustomerAccount | ScheduledPollConsumer
> | 84 - org.apache.camel.camel-core - 2.9.2 | Scheduled task completed on:
> Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
>
>
> Also, please find below the list of features installed in my system along
> with the versions.
>
> karaf@root> features:list | grep -w installed
> [installed  ] [3.0.7.RELEASE  ] spring
> karaf-2.2.7
> [installed  ] [1.2.1          ] spring-dm
> karaf-2.2.7
> [installed  ] [3.0.7.RELEASE  ] spring-jdbc
> karaf-2.2.7
> [installed  ] [3.0.7.RELEASE  ] spring-jms
> karaf-2.2.7
> [installed  ] [3.0.7.RELEASE  ] spring-orm
> karaf-2.2.7
> [installed  ] [3.0.7.RELEASE  ] spring-tx
> karaf-2.2.7
> [installed  ] [3.0.7.RELEASE  ] spring-web
> karaf-2.2.7
> [installed  ] [2.2.7          ] config
> karaf-2.2.7
> [installed  ] [7.5.4.v20111024] jetty
> karaf-2.2.7
> [installed  ] [2.2.7          ] http
> karaf-2.2.7
> [installed  ] [2.2.7          ] kar
> karaf-2.2.7
> [installed  ] [2.2.7          ] webconsole-base
> karaf-2.2.7
> [installed  ] [2.2.7          ] webconsole
> karaf-2.2.7
> [installed  ] [2.2.7          ] ssh
> karaf-2.2.7
> [installed  ] [2.2.7          ] management
> karaf-2.2.7
> [installed  ] [0.3            ] transaction
> karaf-enterprise-2.2.7 OSGi Transaction Manager
> [installed  ] [0.3            ] jpa
> karaf-enterprise-2.2.7 OSGi Persistence Container
> [installed  ] [0.3            ] jndi
> karaf-enterprise-2.2.7 OSGi Service Registry JNDI access
> [installed  ] [1.9.0          ] xml-specs-api
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-core
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-spring
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-blueprint
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-cxf
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-http4
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-jackson
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-jpa
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-mybatis
> camel-2.9.2
> [installed  ] [2.9.2          ] camel-xstream
> camel-2.9.2
> [installed  ] [2.5.2          ] cxf-specs
> cxf-2.5.2
> [installed  ] [2.5.2          ] cxf-jaxb
> cxf-2.5.2
> [installed  ] [2.5.2          ] cxf-abdera
> cxf-2.5.2
> [installed  ] [2.5.1_1        ] opensaml
> cxf-2.5.2
> [installed  ] [1.6.4          ] wss4j
> cxf-2.5.2
> [installed  ] [2.5.2          ] cxf-saaj-impl
> cxf-2.5.2
> [installed  ] [2.5.2          ] cxf-war-java5
> cxf-2.5.2
> [installed  ] [2.5.2          ] cxf
> cxf-2.5.2
>
> best regards
> Sriraman.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5714893.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by Sriraman Gopalan <sr...@gmail.com>.
Hi Claus,

Thanks for the quick reply.

Please find below the complete log from the point the consumer poll is
started till it is completed:

2012-06-22 12:11:20,178 | TRACE | .CustomerAccount | ScheduledPollConsumer           
| 84 - org.apache.camel.camel-core - 2.9.2 | Scheduled task started on:  
Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
2012-06-22 12:11:20,179 | TRACE | .CustomerAccount | ScheduledPollConsumer           
| 84 - org.apache.camel.camel-core - 2.9.2 | Starting to poll:
Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
2012-06-22 12:11:20,179 | DEBUG | .CustomerAccount | JpaTransactionManager           
| 77 - org.springframework.transaction - 3.0.7.RELEASE | Creating new
transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2012-06-22 12:11:20,180 | DEBUG | .CustomerAccount | JpaTransactionManager           
| 77 - org.springframework.transaction - 3.0.7.RELEASE | Opened new
EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@3192caa9] for JPA
transaction
2012-06-22 12:11:20,180 | DEBUG | .CustomerAccount | JpaTransactionManager           
| 77 - org.springframework.transaction - 3.0.7.RELEASE | Could not rollback
EntityManager after failed transaction begin
<openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.
	at
org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:551)[176:org.apache.openjpa:2.1.1]
	at
org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:101)[176:org.apache.openjpa:2.1.1]
	at
org.apache.aries.jpa.container.impl.EntityManagerWrapper.getTransaction(EntityManagerWrapper.java:153)[54:org.apache.aries.jpa.container:0.3.0]
	at
org.springframework.orm.jpa.JpaTransactionManager.closeEntityManagerAfterFailedBegin(JpaTransactionManager.java:412)[170:org.springframework.orm:3.0.7.RELEASE]
	at
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:381)[170:org.springframework.orm:3.0.7.RELEASE]
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)[77:org.springframework.transaction:3.0.7.RELEASE]
	at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)[77:org.springframework.transaction:3.0.7.RELEASE]
	at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[177:org.apache.camel.camel-jpa:2.9.2]
	at
org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:81)[177:org.apache.camel.camel-jpa:2.9.2]
	at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138)[84:org.apache.camel.camel-core:2.9.2]
	at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90)[84:org.apache.camel.camel-core:2.9.2]
	at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_29]
	at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_29]
	at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_29]
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
	at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
2012-06-22 12:11:20,180 | DEBUG | .CustomerAccount |
EntityManagerFactoryUtils        | 170 - org.springframework.orm -
3.0.7.RELEASE | Closing JPA EntityManager
2012-06-22 12:11:20,183 | WARN  | .CustomerAccount |
faultPollingConsumerPollStrategy | 84 - org.apache.camel.camel-core - 2.9.2
| Consumer
Consumer[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
could not poll endpoint:
Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]
caused by: Could not open JPA EntityManager for transaction; nested
exception is <openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.
org.springframework.transaction.CannotCreateTransactionException: Could not
open JPA EntityManager for transaction; nested exception is
<openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.
	at
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:382)[170:org.springframework.orm:3.0.7.RELEASE]
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)[77:org.springframework.transaction:3.0.7.RELEASE]
	at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)[77:org.springframework.transaction:3.0.7.RELEASE]
	at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[177:org.apache.camel.camel-jpa:2.9.2]
	at
org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:81)[177:org.apache.camel.camel-jpa:2.9.2]
	at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138)[84:org.apache.camel.camel-core:2.9.2]
	at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90)[84:org.apache.camel.camel-core:2.9.2]
	at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_29]
	at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_29]
	at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_29]
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
	at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
Caused by: <openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.
	at
org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:551)[176:org.apache.openjpa:2.1.1]
	at
org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:101)[176:org.apache.openjpa:2.1.1]
	at
org.apache.aries.jpa.container.impl.EntityManagerWrapper.getTransaction(EntityManagerWrapper.java:153)[54:org.apache.aries.jpa.container:0.3.0]
	at
org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)[170:org.springframework.orm:3.0.7.RELEASE]
	at
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:332)[170:org.springframework.orm:3.0.7.RELEASE]
	... 15 more
2012-06-22 12:11:20,185 | TRACE | .CustomerAccount | ScheduledPollConsumer           
| 84 - org.apache.camel.camel-core - 2.9.2 | Scheduled task completed on:
Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000?persistenceUnit=pdsprint1&consumer.namedQuery=selectAllCustomerAccounts]


Also, please find below the list of features installed in my system along
with the versions.

karaf@root> features:list | grep -w installed   
[installed  ] [3.0.7.RELEASE  ] spring                               
karaf-2.2.7            
[installed  ] [1.2.1          ] spring-dm                            
karaf-2.2.7            
[installed  ] [3.0.7.RELEASE  ] spring-jdbc                          
karaf-2.2.7            
[installed  ] [3.0.7.RELEASE  ] spring-jms                           
karaf-2.2.7            
[installed  ] [3.0.7.RELEASE  ] spring-orm                           
karaf-2.2.7            
[installed  ] [3.0.7.RELEASE  ] spring-tx                            
karaf-2.2.7            
[installed  ] [3.0.7.RELEASE  ] spring-web                           
karaf-2.2.7            
[installed  ] [2.2.7          ] config                               
karaf-2.2.7            
[installed  ] [7.5.4.v20111024] jetty                                
karaf-2.2.7            
[installed  ] [2.2.7          ] http                                 
karaf-2.2.7            
[installed  ] [2.2.7          ] kar                                  
karaf-2.2.7            
[installed  ] [2.2.7          ] webconsole-base                      
karaf-2.2.7            
[installed  ] [2.2.7          ] webconsole                           
karaf-2.2.7            
[installed  ] [2.2.7          ] ssh                                  
karaf-2.2.7            
[installed  ] [2.2.7          ] management                           
karaf-2.2.7            
[installed  ] [0.3            ] transaction                          
karaf-enterprise-2.2.7 OSGi Transaction Manager
[installed  ] [0.3            ] jpa                                  
karaf-enterprise-2.2.7 OSGi Persistence Container
[installed  ] [0.3            ] jndi                                 
karaf-enterprise-2.2.7 OSGi Service Registry JNDI access
[installed  ] [1.9.0          ] xml-specs-api                        
camel-2.9.2            
[installed  ] [2.9.2          ] camel-core                           
camel-2.9.2            
[installed  ] [2.9.2          ] camel-spring                         
camel-2.9.2            
[installed  ] [2.9.2          ] camel-blueprint                      
camel-2.9.2            
[installed  ] [2.9.2          ] camel-cxf                            
camel-2.9.2            
[installed  ] [2.9.2          ] camel-http4                          
camel-2.9.2            
[installed  ] [2.9.2          ] camel-jackson                        
camel-2.9.2            
[installed  ] [2.9.2          ] camel-jpa                            
camel-2.9.2            
[installed  ] [2.9.2          ] camel-mybatis                        
camel-2.9.2            
[installed  ] [2.9.2          ] camel-xstream                        
camel-2.9.2            
[installed  ] [2.5.2          ] cxf-specs                            
cxf-2.5.2              
[installed  ] [2.5.2          ] cxf-jaxb                             
cxf-2.5.2              
[installed  ] [2.5.2          ] cxf-abdera                           
cxf-2.5.2              
[installed  ] [2.5.1_1        ] opensaml                             
cxf-2.5.2              
[installed  ] [1.6.4          ] wss4j                                
cxf-2.5.2              
[installed  ] [2.5.2          ] cxf-saaj-impl                        
cxf-2.5.2              
[installed  ] [2.5.2          ] cxf-war-java5                        
cxf-2.5.2              
[installed  ] [2.5.2          ] cxf                                  
cxf-2.5.2 

best regards
Sriraman.

--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5714893.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Can you post the real stacktrace? Usually the have line numbers and whatnot.
Also mention the Camel and Karaf version you use.



On Thu, Jun 21, 2012 at 9:35 AM, Sriraman Gopalan <sr...@gmail.com> wrote:
> Dear All,
>
> I have a camel route that polls the database (using a jpa consumer) as shown
> below:
>
> Camel Route:
>
> =================================================================
> from("jpa:samples.CustomerAccount?consumer.namedQuery=selectAllCustomerAccounts&consumeDelete=false")
> .to("log:test-out")
>
> My persistence.xml is as follows:
> =================================================================
> <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="pdsprint1" transaction-type="JTA">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
> <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/pdsprint1)</jta-data-source>
>
>        <class>samples.CustomerAccount</class>
>        <class>samples.AccountInfo</class>
>
>        <exclude-unlisted-classes>true</exclude-unlisted-classes>
>
>        <properties>
>            <property name="openjpa.ConnectionFactoryMode" value="managed"/>
>            <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema"/>
>            <property name="openjpa.jdbc.DBDictionary"
> value="org.apache.openjpa.jdbc.sql.H2Dictionary"/>
>            <property name="openjpa.ManagedRuntime"
> value="jndi(TransactionManagerName=osgi:service/javax.transaction.TransactionManager)"/>
>            <property name="openjpa.Log" value="DefaultLevel=TRACE,
> Tool=INFO" />
>        </properties>
>    </persistence-unit>
>
> </persistence>
>
> ================================================================
>
> My blueprint configuration is as follows:
>
> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>                <tx:transaction method="*" />
>                <property name="entityManagerFactory" ref="entityManagerFactory" />
>                <property name="transactionManager" ref="transactionManager" />
> </bean>
>
> <bean id="transactionManager"
> class="org.springframework.orm.jpa.JpaTransactionManager">
>                <property name="entityManagerFactory" ref="entityManagerFactory" />
> </bean>
>
> <reference id="entityManagerFactory"
> interface="javax.persistence.EntityManagerFactory"
> filter="(osgi.unit.name=pdsprint1)" />
>
> =================================================================
>
> However, I am getting the following error when I start the bundle:
>
> Consumer[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000&consumer.namedQuery=selectAllCustomerAccounts]
> could not poll endpoint:
> Endpoint[jpa://samples.CustomerAccount?consumeDelete=false?consumer.delay=10000&consumer.namedQuery=selectAllCustomerAccounts]
> caused by: Could not open JPA EntityManager for transaction; nested
> exception is <openjpa-2.1.1-r422266:1148538 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: You cannot access the
> EntityTransaction when using managed transactions.
> org.springframework.transaction.CannotCreateTransactionException: Could not
> open JPA EntityManager for transaction; nested exception is
> <openjpa-2.1.1-r422266:1148538 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException: You cannot access the
> EntityTransaction when using managed transactions.
>
> Note:
>
> I have the following features installed in Karaf:
>
> 1. jpa
> 2. jndi
> 3. transaction
> 4. camel-jpa
>
> Also, my data source is configured via another bundle as shown below as
> suggested by
> Christian Schneider in his blog
>
> http://www.liquid-reality.de/display/liquid/2012/01
>
> =================================================================
>
> <cm:property-placeholder persistent-id="samples.datasource">
>        </cm:property-placeholder>
>
>        <bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
>                <property name="URL" value="${db.url}" />
>                <property name="user" value="${db.userid}" />
>                <property name="password" value="${db.password}" />
>        </bean>
>
>        <service interface="javax.sql.DataSource" ref="dataSource">
>                <service-properties>
>                        <entry key="osgi.jndi.service.name" value="jdbc/pdsprint1" />
>                </service-properties>
>        </service>
>
> =================================================================
> Can somebody point me in the right direction?
>
> best regards
> Sriraman.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by doxumd <do...@yahoo.com>.
Hi Claus 

Thanks for your quick reply. I've added dependencies to aries and now I have
a new issue :( 

[         Blueprint Extender: 1] BlueprintContainerImpl         INFO  Bundle
RouteTest is waiting for dependencies
[(&(&(!(org.apache.aries.jpa.proxy.factory=*))(osgi.unit.name=jpa-example-pu))(objectClass=javax.persistence.EntityManagerFactory))]


something similar to this 
link
<http://mail-archives.apache.org/mod_mbox/aries-user/201201.mbox/%3C4F0FE64D.2050800@die-schneider.net%3E>  




--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5730297.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You would need to add to the classpath the Aries JPA JARs that has
that JPA stuff you use.
I am not sure which one has it but there is a bunch of Aries JPA JARs
http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.aries.jpa%22


On Wed, Apr 3, 2013 at 9:49 AM, doxumd <do...@yahoo.com> wrote:
> I need your help, I'm using pretty much the same example with a RouteTest
> class and it does not work as expected because of the following line :
>
> Bundle RouteTest is waiting for namespace handlers
> [http://aries.apache.org/xmlns/jpa/v1.1.0]
>
>
> I'm using the following blueprint.xml :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xmlns:camel="http://camel.apache.org/schema/blueprint"
>
> xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
>         xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
>         xsi:schemaLocation="
>                 http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
>                 http://camel.apache.org/schema/blueprint
> http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
>                 http://aries.apache.org/xmlns/jpa/v1.1.0
> http://aries.apache.org/schemas/jpa/jpa_110.xsd">
>
>     <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>         <jpa:unit unitname="persistence-pu" property="entityManagerFactory"
> />
>     </bean>
>
>     <camelContext trace="true" id="blueprintContext"
> xmlns="http://camel.apache.org/schema/blueprint">
>     <route id="persist">
>         <from uri="direct:persist"/>
>         <to uri="jpa:Person"/>
>     </route>
> </camelContext>
> </blueprint>
>
>
> and the following RouteTest.java
>
> public class RouteTest extends CamelBlueprintTestSupport {
>
>     @Override
>     protected String getBlueprintDescriptor() {
>         return "/OSGI-INF/blueprint/blueprint.xml";
>     }
>
>     @Test
>     public void testRoute() throws Exception {
>         getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
>         ProducerTemplate producerTemplate = new
> DefaultCamelContext().createProducerTemplate();
>         Person person = new Person();
>         person.setName("Bob");
>         producerTemplate.sendBody("direct:persist", person);
>
>         // assert expectations
>         assertMockEndpointsSatisfied();
>     }
>
> }
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5730257.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Problem with Camel Jpa Component and Container Managed Transaction

Posted by doxumd <do...@yahoo.com>.
I need your help, I'm using pretty much the same example with a RouteTest
class and it does not work as expected because of the following line :

Bundle RouteTest is waiting for namespace handlers
[http://aries.apache.org/xmlns/jpa/v1.1.0]


I'm using the following blueprint.xml : 

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:camel="http://camel.apache.org/schema/blueprint"
       
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
        xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
        xsi:schemaLocation="
                http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
                http://camel.apache.org/schema/blueprint
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
                http://aries.apache.org/xmlns/jpa/v1.1.0
http://aries.apache.org/schemas/jpa/jpa_110.xsd">

    <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
        <jpa:unit unitname="persistence-pu" property="entityManagerFactory"
/>
    </bean>

    <camelContext trace="true" id="blueprintContext"
xmlns="http://camel.apache.org/schema/blueprint">
    <route id="persist">
        <from uri="direct:persist"/>
        <to uri="jpa:Person"/>
    </route>
</camelContext>
</blueprint>


and the following RouteTest.java

public class RouteTest extends CamelBlueprintTestSupport {

    @Override
    protected String getBlueprintDescriptor() {
        return "/OSGI-INF/blueprint/blueprint.xml";
    }

    @Test
    public void testRoute() throws Exception {
        getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
        ProducerTemplate producerTemplate = new
DefaultCamelContext().createProducerTemplate(); 
        Person person = new Person();
        person.setName("Bob");
        producerTemplate.sendBody("direct:persist", person);

        // assert expectations
        assertMockEndpointsSatisfied();
    }

}




--
View this message in context: http://camel.465427.n5.nabble.com/Problem-with-Camel-Jpa-Component-and-Container-Managed-Transaction-tp5714815p5730257.html
Sent from the Camel - Users mailing list archive at Nabble.com.