You should use from("jpa:xxx") And you can set the consumer.delay=2m
to poll every 2nd minute.


On Fri, Jul 4, 2014 at 11:11 AM, chanducompute
<[email protected]> wrote:
> Hi,
>
> I am new camel and tried using JPA end point in my code.
>
> Belos is the Java DSL route
> from("timer:refresh?period=2m")
>
> .to("jpa:com.test.persistence.entity.ParameterMappings?consumer.namedQuery=chandra")
>                                 .log("${body}");
>
> Here is my persistence.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.0"
>         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";>
>
>         <persistence-unit name="OpsConsoleDB"
> transaction-type="RESOURCE_LOCAL">
>
>                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
>
> <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
>
>
>
>                 <class>com.test.persistence.entity.ParameterMappings</class>
>
>                 <properties>
>                         <property name="hibernate.default_schema"
> value="opsBridge" />
>                         <property name="hibernate.dialect"
> value="org.hibernate.dialect.PostgreSQLDialect" />
>                         <property name="hibernate.jdbc.batch_size"
> value="20" />
>                         <property
> name="hibernate.transaction.manager_lookup_class"
> value="org.hibernate.transaction.JBossTransactionManagerLookup" />
>                         <property name="hibernate.show_sql" value="true" />
>                 </properties>
>         </persistence-unit>
> </persistence>
>
> Below is my camel context file snippet
> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>                 <property name="entityManagerFactory" ref="opsEMFactory" />
>                 <property name="transactionManager" ref="opsTxManager" />
>         </bean>
>
>         <bean id="opsTxManager"
> class="org.springframework.orm.jpa.JpaTransactionManager">
>                 <property name="entityManagerFactory" ref="opsEMFactory" />
>         </bean>
>
>         <bean id="opsEMFactory"
>
> class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
>                 <property name="persistenceUnitName" value="OpsConsoleDB" />
>         </bean>
>
> When I deploy the application. The camel is invoking the timer component but
> at JPA execution I am getting the below exception.
> Exchange
> ---------------------------------------------------------------------------------------------------------------------------------------
> Exchange[
>         Id                  ID-E0685F1L-50180-1404458135473-0-2
>         ExchangePattern     InOnly
>         Headers
> {breadcrumbId=ID-E0685F1L-50180-1404458135473-0-1,
> CamelEntityManager=org.hibernate.ejb.EntityManagerImpl@79de0e,
> CamelRedelivered=false, CamelRedeliveryCounter=0, firedTime=Fri Jul 04
> 12:45:37 IST 2014}
>         BodyType            null
>         Body                [Body is null]
> ]
>
> Stacktrace
> ---------------------------------------------------------------------------------------------------------------------------------------:
> org.apache.camel.InvalidPayloadRuntimeException: No body available of type:
> com.test.persistence.entity.ParameterMappings on: Message: [Body is null].
> Caused by: No type converter available to convert from type: null to the
> required type: com.test.persistence.entity.ParameterMappings with value null
> on the exchange: Exchange[Message: [Body is null]]
>         at
> org.apache.camel.component.jpa.JpaEndpoint$1.evaluate(JpaEndpoint.java:289)
> [camel-jpa-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:56)
> [camel-jpa-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:132)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:307)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:127)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
> [camel-core-2.12.2.jar:2.12.2]
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
> [camel-core-2.12.2.jar:2.12.2]
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:139)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:64)
> [camel-core-2.12.2.jar:2.12.2]
>         at java.util.TimerThread.mainLoop(Timer.java:555) [rt.jar:1.7.0_51]
>         at java.util.TimerThread.run(Timer.java:505) [rt.jar:1.7.0_51]
> Caused by: org.apache.camel.NoTypeConversionAvailableException: No type
> converter available to convert from type: null to the required type:
> com.test.persistence.entity.ParameterMappings with value null
>         at
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:181)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
> [camel-core-2.12.2.jar:2.12.2]
>         at
> org.apache.camel.component.jpa.JpaEndpoint$1.evaluate(JpaEndpoint.java:286)
> [camel-jpa-2.12.2.jar:2.12.2]
>         ... 16 more
>
> ======
> Can some one please help me resolve this?
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Camel-JPA-endpoint-consumer-problem-tp5753332.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [email protected]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Reply via email to