Reputation: 599
I faced the following problem with JPA but it's maybe more like a conceptional question about Camel.
I need a cron based Quartz consumer. But if it's triggered, I'd like to make a selection as a 1st step with JPA component.
<from uri="quartz://myQuartz?cron=myCronExpression/>
<to uri="jpa://home.myEntity?consumer.query=select o from home.myEntity o"/>
But if I call the JPA component with "to", then it's used as a Producer, and not as a Consumer. Can I use somehow the JPA component to handle this, or I have to follow the Service Activator (bean-based) logic and leave the JPA component behind?
Thanks in advance, Gergely
Upvotes: 3
Views: 3276
Reputation: 4349
Very good point Petter. I had a similar issue. I wanted to create a simple route that when called will retrieve data from the database. The solutions is simple.
from("direct:test")
.pollEnrich("jpa://" + User.class.getName() + "?consumer.query=select u from test.User u&consumeDelete=false")
Also check this Camel - content enricher: enrich() vs pollEnrich().
Upvotes: 1
Reputation: 22279
This is pretty much the Content-Enrichement pattern. You can use the
<pollEnrich uri="jpa://home.myEntity?consumer.query=select o from home.myEntity o"/>
instead to use a consumer mid-route. Keep in mind that you cannot use runtime data from the route (headers or the like) but need to keep the route URI static in this case. Seems your URI is static so that should be no issue.
Upvotes: 4