0

A "named query" I'm using in a Processor.process() method doesn't work

--Why? -How can I fix it?

thx for any help! :-)

This is the JPA entity with the "named query" in question...

i.e.,

@NamedQuery(name = "ThingTable.byUpdateTs", query = "SELECT e FROM ThingTable e WHERE e.updateTs > :updateTs")

The "named query" is used in the process method code (below), but, is not working...

i.e.,

@Override
public void process(Exchange msg) throws Exception {
    String firedTime = msg.getIn().getHeader("firedTime", String.class);

    ZonedDateTime zdtnow = ZonedDateTime.parse(firedTime, formatter2);
    zdtnow = zdtnow.withZoneSameInstant(ZoneId.of("America/New_York")); // ...in case springboot server defaults to UTC/GMT time zone...

    ZonedDateTime startZDT = zdtnow.minusMonths(24); //.minusSeconds(65); 
    
    //*********** this is the line of code using the "named query" ********** 
    String pollingQuery="jpa:aaa.bbb.ccc.jar.ThingTable?namedQuery=ThingTable.byUpdateTs&updateTs='" + startZDT.format(formatter) + "'";

    msg.getIn().setBody(pollingQuery);
}

The Processor.process() method is used in this camel route...

i.e.,

from("timer://pollingTimer?fixedRate=true&period=60000")
        .process(theProcessor::process)
        .toD("${body}")
        .split(body())
        .convertBodyTo(java.lang.String.class, "UTF-8")
        .log("===============>>> NEW MESSAGE: ${body}");  

a snippet of stacktrace describing error:

i.e.,

-
-
-
2020-12-30 23:53:32.191 ERROR 1 --- [://pollingTimer] o.a.c.p.e.DefaultErrorHandler            : Failed delivery for (MessageId: ID-7499dc21186b-1609372412151-0-1 on ExchangeId: ID-7499dc21186b-1609372412151-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{updateTs='2018-12-30 18:53:31'}]

Message History (complete message history is disabled)
---------------------------------------------------------------------------------------------------------------------------------------

RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [from[timer://pollingTimer?fixedRate=true&period=60000]                        ] [       333]
 ...
[route1            ] [toD1              ] [${body}                                                                       ] [         0]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------


org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: Failed to resolve endpoint: jpa://aaa.bbb.ccc.jar.ThingTable?namedQuery=byUpdateTs&updateTs=%272018-12-30+18%3A53%3A31%27 due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{updateTs='2018-12-30 18:53:31'}]
 at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:876) ~[camel-base-3.3.0.jar!/:3.3.0]
 at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:771) ~[camel-base-3.3.0.jar!/:3.3.0]
 at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:72) ~[camel-support-3.3.0.jar!/:3.3.0]
 at org.apache.camel.support.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:114) ~[camel-support-3.3.0.jar!/:3.3.0]
 at org.apache.camel.support.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:92) ~[camel-support-3.3.0.jar!/:3.3.0]
 at org.apache.camel.processor.SendDynamicProcessor.resolveEndpoint(SendDynamicProcessor.java:287) ~[camel-base-3.3.0.jar!/:3.3.0]
 at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:155) ~[camel-base-3.3.0.jar!/:3.3.0]
 at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:395) ~[camel-base-3.3.0.jar!/:3.3.0]
 at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148) ~[camel-base-3.3.0.jar!/:3.3.0]
 at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60) ~[camel-base-3.3.0.jar!/:3.3.0]
 -
 -
 -
 
 

(Tried apache camel.apache.org website, but, so far, have been unable to find an example "named query" example that uses parameters - like mine, above)

e.g., https://camel.apache.org/components/latest/jpa-component.html)

sairn
  • 461
  • 3
  • 24
  • 58
  • 1
    Does this answer your question? [how to pass namedQuery parameters in Apache Camel JPA by header?](https://stackoverflow.com/questions/43836518/how-to-pass-namedquery-parameters-in-apache-camel-jpa-by-header) – Chin Huang Dec 31 '20 at 16:55

1 Answers1

0

You have specified the option updateTs which is not a known option for the JPA component.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Hi Claus - "updateTs" is a property in the entity class and it corresponds to a column in the "ThingTable" table (I also I used it as a variable name in the named query: "SELECT e FROM ThingTable e WHERE e.updateTs > :updateTs"). --Is my syntax incorrect? thx – sairn Dec 31 '20 at 13:56
  • ...to further clarify, I had though that in the process() method, [&updateTs='" + startZDT.format(formatter)] was assigning a value to the parameter - ":updateTs" in the where clause of the named query - i.e., [WHERE e.updateTs > :updateTs]... – sairn Dec 31 '20 at 14:04