Thanks for your answer. Unfortunately, I have to use Camel 3.4 for now. However, it is good to know there is a possibility it might work in future release.
Regards, Calle ________________________________ Från: Claus Ibsen <claus.ib...@gmail.com> Skickat: onsdag 25 augusti 2021 06:56 Till: users@camel.apache.org Ämne: Re: Passing exchange header into JPA component query Hi You can try test this with 3.11.x as there has been a number of improvements and bug fixes in the endpoint-dsl and whatnot since this release. On Tue, Aug 24, 2021 at 6:39 PM Calle Andersson <calleanders...@hotmail.com> wrote: > > Hi, > > I use Camel 3.4 and have a question regarding the JPA component. > > I have the following query: > SELECT c FROM " + MyEntity.class.getName() + " c WHERE c.dummy = :myParam > > I have been trying to get the following configuration to work (using Endpoint > DSL): > .toD(jpa(MyEntity.class.getName()).query("SELECT c FROM " + > MyEntity.class.getName() + " c WHERE c.dummy = ${headers.myParam}")) > > But then I get the following Exception: > org.hibernate.QueryException: unexpected char: '{' [SELECT c FROM > se.test.MyEntity c WHERE c.dummy = ${headers.myParam}] > > While googling, I have seen someone claim that the configuration above should > work. Is this something that works in later versions of Camel or is it a dead > end? > > I have been able to make the query work with the following solution: > .process(exchange -> { > Map<String, Object> map = new HashMap<String, Object>(); > map.put("myParam", exchange.getIn().getHeader("myParam")); > exchange.getIn().setHeader(JpaConstants.JPA_PARAMETERS_HEADER, map); > }) > .to(jpa(MyEntity.class.getName()).query("SELECT c FROM " + > MyEntity.class.getName() + " c WHERE c.dummy = :myParam")) > > Could this be solved in a more elegant way? > > Thanks in advance, > Calle -- Claus Ibsen ----------------- http://davsclaus.com @davsclaus Camel in Action 2: https://www.manning.com/ibsen2