You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lmanchanda75 <lm...@gmail.com> on 2013/05/27 09:19:18 UTC

camel jpa issue

hi,

I am having an issue in application using jpa (as consumer), following is
the camel context.

<?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: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="purchaseOrder" class="manchanda.lalit.TestJpa.PurchaseOrder"/>

  <camelContext trace="false" id="blueprintContext"
xmlns="http://camel.apache.org/schema/blueprint">
   <camel:route id="fetch-from-db-print">
   <from uri="jpa://manchanda.lalit.TestJpa.PurchaseOrder"/>
   <to uri="log:manchanda.lalit.TestJpa.PurchaseOrder?level=DEBUG" />
   </camel:route>
</camelContext>

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


	 <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource"
destroy-method="close">
      <property name="serverName" value="localhost:5432/AMP"/>
      <property name="user" value="postgres"/>
      <property name="password" value="airtel@123"/>
      <property name="dataSourceName" value="myConnectionPool"/>
      <property name="initialConnections" value="2"/>
      <property name="maxConnections" value="4" />
  </bean>
  
  <service interface="javax.sql.DataSource" ref="dataSource">
    <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/postgresds"/>
    </service-properties>
  </service>

</blueprint>




Following is the persistence.xml


<?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" version="1.0">
 
  <persistence-unit name="camel-openjpa" transaction-type="RESOURCE_LOCAL">
  <provider>
         org.apache.openjpa.persistence.PersistenceProviderImpl
   </provider>
  
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/postgresds</jta-data-source>
  
<non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/postgresds)</non-jta-data-source>
     <class>manchanda.lalit.TestJpa.PurchaseOrder</class>
     <exclude-unlisted-classes>true</exclude-unlisted-classes>
    
    <properties>
      <property name="openjpa.Log" value="DefaultLevel=INFO, Tool=INFO"/>
      <property name="openjpa.jdbc.DBDictionary" value="postgres"/>
      <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
    </properties>

  </persistence-unit>

    
</persistence>



*When I start the application I get the following error, seems I am missing
something basic, though I have checked some samples but no way forward.*

22:32:25,963 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Creating new
transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT^M
22:32:25,963 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Opened new
EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e2510c] for JPA
transaction^M
22:32:25,966 | DEBUG | pa.PurchaseOrder | JpaConsumer                      |
244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Acquiring exclusive
lock on entity: null^M
22:32:25,966 | DEBUG | pa.PurchaseOrder | JpaConsumer                      |
244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Failed to achieve
lock on entity: null. Reason: java.lang.IllegalArgumentException: lock can
not be invoked on "null". This entity is either detached or not persistent
or null.^M
java.lang.IllegalArgumentException: lock can not be invoked on "null". This
entity is either detached or not persistent or null.^M
        at
org.apache.openjpa.persistence.EntityManagerImpl.assertValidAttchedEntity(EntityManagerImpl.java:1385)[243:org.apache.openjpa:2.2.0]^M
        at
org.apache.openjpa.persistence.EntityManagerImpl.lock(EntityManagerImpl.java:1199)[243:org.apache.openjpa:2.2.0]^M
        at
org.apache.openjpa.persistence.EntityManagerImpl.lock(EntityManagerImpl.java:1188)[243:org.apache.openjpa:2.2.0]^M
        at
org.apache.aries.jpa.container.impl.EntityManagerWrapper.lock(EntityManagerWrapper.java:169)^M
        at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)^M
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_43]^M
        at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_43]^M
        at
org.springframework.orm.jpa.JpaTemplate$CloseSuppressingInvocationHandler.invoke(JpaTemplate.java:429)[242:org.springframework.orm:3.1.3.RELEASE]^M
        at com.sun.proxy.$Proxy42.lock(Unknown
Source)[256:org.apache.aries.jpa.container:1.0.1.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer.lockEntity(JpaConsumer.java:262)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer.processBatch(JpaConsumer.java:150)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer$1.doInJpa(JpaConsumer.java:97)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1$1.doInJpa(JpaTemplateTransactionStrategy.java:82)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:187)[242:org.springframework.orm:3.1.3.RELEASE]^M
        at
org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:150)[242:org.springframework.orm:3.1.3.RELEASE]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1.doInTransaction(JpaTemplateTransactionStrategy.java:80)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)[136:org.springframework.transaction:3.1.3.RELEASE]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:75)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:142)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]^M
        at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]^M
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)[:1.6.0_43]^M
        at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_43]^M
        at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_43]^M
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)[:1.6.0_43]^M
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)[:1.6.0_43]^M
        at java.lang.Thread.run(Thread.java:662)[:1.6.0_43]^M
22:32:25,970 | WARN  | pa.PurchaseOrder | JpaConsumer                      |
244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Error processing
last message due: java.lang.NullPointerException. Will commit all previous
successful processed message, and ignore this last failure.^M
javax.persistence.PersistenceException: java.lang.NullPointerException^M
        at
org.apache.camel.component.jpa.JpaConsumer$1.doInJpa(JpaConsumer.java:102)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1$1.doInJpa(JpaTemplateTransactionStrategy.java:82)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:187)[242:org.springframework.orm:3.1.3.RELEASE]^M
 at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1.doInTransaction(JpaTemplateTransactionStrategy.java:80)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)[136:org.springframework.transaction:3.1.3.RELEASE]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:75)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:142)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]^M
        at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]^M
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)[:1.6.0_43]^M
        at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_43]^M
        at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_43]^M
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)[:1.6.0_43]^M
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)[:1.6.0_43]^M
        at java.lang.Thread.run(Thread.java:662)[:1.6.0_43]^M
22:32:25,970 | WARN  | pa.PurchaseOrder | JpaConsumer                      |
244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Error processing
last message due: java.lang.NullPointerException. Will commit all previous
successful processed message, and ignore this last failure.^M
javax.persistence.PersistenceException: java.lang.NullPointerException^M
        at
org.apache.camel.component.jpa.JpaConsumer$1.doInJpa(JpaConsumer.java:102)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1$1.doInJpa(JpaTemplateTransactionStrategy.java:82)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:187)[242:org.springframework.orm:3.1.3.RELEASE]^M
        at
org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:150)[242:org.springframework.orm:3.1.3.RELEASE]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy$1.doInTransaction(JpaTemplateTransactionStrategy.java:80)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)[136:org.springframework.transaction:3.1.3.RELEASE]^M
        at
org.apache.camel.component.jpa.JpaTemplateTransactionStrategy.execute(JpaTemplateTransactionStrategy.java:78)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:75)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:142)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]^M
        at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]^M
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)[:1.6.0_43]^M
        at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_43]^M
        at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_43]^M
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_43]^M
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)[:1.6.0_43]^M
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)[:1.6.0_43]^M
        at java.lang.Thread.run(Thread.java:662)[:1.6.0_43]^M
Caused by: java.lang.NullPointerException^M
        at
org.apache.camel.component.jpa.JpaConsumer.lockEntity(JpaConsumer.java:270)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer.processBatch(JpaConsumer.java:150)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        at
org.apache.camel.component.jpa.JpaConsumer$1.doInJpa(JpaConsumer.java:97)[244:org.apache.camel.camel-jpa:2.10.0.redhat-60024]^M
        ... 18 more^M
22:32:25,971 | DEBUG | pa.PurchaseOrder | JpaConsumer                      |
244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Flushing
EntityManager^M
22:32:25,971 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Initiating
transaction commit^M
22:32:25,972 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Committing JPA
transaction on EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e2510c]^M
22:32:25,972 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Closing JPA
EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e2510c] after
transaction^M





--
View this message in context: http://camel.465427.n5.nabble.com/camel-jpa-issue-tp5733238.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel jpa issue

Posted by lmanchanda75 <lm...@gmail.com>.
Hi Claus,

Thanks. It was the problem. I figured out that I was not using
consumeDelete=false.

Meanwhile I think that by default consumeDelete should be false than true,
as a small mistake can cause data loss in production.

Regds
Lalit




--
View this message in context: http://camel.465427.n5.nabble.com/camel-jpa-issue-tp5733238p5733271.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel jpa issue

Posted by Claus Ibsen <cl...@gmail.com>.
Are you sure there is data in the table? If there is no rows then
there is now data to route.
And also are you sure if there is data, that the logging level at
DEBUG is being logged in your log?

On Mon, May 27, 2013 at 5:21 PM, lmanchanda75 <lm...@gmail.com> wrote:
> I figured this out, the null was coming because of me not defining any
> attribute as @Id in PurchaseOrder entity.
>
> But now when I run this, it goes in a loop of the following, without moving
> to next point it route (log). See if anybody can help me on this.
>
>
> 20:43:50,204 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
> 136 - org.springframework.transaction - 3.1.3.RELEASE | Creating new
> transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT^M
> 20:43:50,205 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
> 136 - org.springframework.transaction - 3.1.3.RELEASE | Opened new
> EntityManager
> [org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e93738] for JPA
> transaction^M
> 20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaConsumer                      |
> 244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Flushing
> EntityManager^M
> 20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
> 136 - org.springframework.transaction - 3.1.3.RELEASE | Initiating
> transaction commit^M
> 20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
> 136 - org.springframework.transaction - 3.1.3.RELEASE | Committing JPA
> transaction on EntityManager
> [org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e93738]^M
> 20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
> 136 - org.springframework.transaction - 3.1.3.RELEASE | Closing JPA
> EntityManager
> [org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e93738] after
> transaction^M
> 20:43:50,213 | DEBUG | pa.PurchaseOrder | EntityManagerFactoryUtils        |
> 242 - org.springframework.orm - 3.1.3.RELEASE | Closing JPA EntityManager^M
> 20:43:50,427 | DEBUG | heckpoint Worker | MessageDatabase                  |
> 114 - org.apache.activemq.activemq-osgi - 5.8.0.redhat-60024 | Checkpoint
> started.^M
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-jpa-issue-tp5733238p5733268.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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: camel jpa issue

Posted by lmanchanda75 <lm...@gmail.com>.
I figured this out, the null was coming because of me not defining any
attribute as @Id in PurchaseOrder entity.

But now when I run this, it goes in a loop of the following, without moving
to next point it route (log). See if anybody can help me on this.


20:43:50,204 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Creating new
transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT^M
20:43:50,205 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Opened new
EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e93738] for JPA
transaction^M
20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaConsumer                      |
244 - org.apache.camel.camel-jpa - 2.10.0.redhat-60024 | Flushing
EntityManager^M
20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Initiating
transaction commit^M
20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Committing JPA
transaction on EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e93738]^M
20:43:50,213 | DEBUG | pa.PurchaseOrder | JpaTransactionManager            |
136 - org.springframework.transaction - 3.1.3.RELEASE | Closing JPA
EntityManager
[org.apache.aries.jpa.container.impl.EntityManagerWrapper@1e93738] after
transaction^M
20:43:50,213 | DEBUG | pa.PurchaseOrder | EntityManagerFactoryUtils        |
242 - org.springframework.orm - 3.1.3.RELEASE | Closing JPA EntityManager^M
20:43:50,427 | DEBUG | heckpoint Worker | MessageDatabase                  |
114 - org.apache.activemq.activemq-osgi - 5.8.0.redhat-60024 | Checkpoint
started.^M




--
View this message in context: http://camel.465427.n5.nabble.com/camel-jpa-issue-tp5733238p5733268.html
Sent from the Camel - Users mailing list archive at Nabble.com.