camel-jpa query - select with parameters

2k views Asked by At

I'm trying to use the jpa component to select by id that i get from the header. I found an example in documentation that uses the native select query:

from("direct:query").to("jpa://org.apache.camel.examples.MultiSteps?query=
select o from org.apache.camel.examples.MultiSteps o where o.step = 1");

I tried to replace the "1" constant with ${header.id}:

from("direct:query").to("jpa://org.apache.camel.examples.MultiSteps?query=
select o from org.apache.camel.examples.MultiSteps o where o.step = ${header.id}");

It doesn't seem to work, i get:

org.hibernate.QueryException: unexpected char: '{'

Maybe there is another way to make that work?

1

There are 1 answers

0
Pashok On

I managed to solve this, based on this question:

Just needed to use toD instead of to:

from("direct:query").toD("jpa://org.apache.camel.examples.MultiSteps?query=
select o from org.apache.camel.examples.MultiSteps o where o.step = ${header.id}");