【问题标题】:Why does a "named query" I'm using in a Processor.process() method not work.? -how can I fixi it?为什么我在 Processor.process() 方法中使用的“命名查询”不起作用。? - 我怎样才能修复它?
【发布时间】:2020-12-31 00:10:13
【问题描述】:

我在 Processor.process() 方法中使用的“命名查询”不起作用

--为什么? -我该如何解决?

感谢您的帮助! :-)

这是有问题的“命名查询”的 JPA 实体...

即,

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

“命名查询”用于处理方法代码(如下),但是,工作...

即,

@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);
}

这个骆驼路线使用了Processor.process()方法……

即,

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}");  

堆栈跟踪描述错误的 sn-p:

即,

-
-
-
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]
 -
 -
 -
 
 

尝试过 apache camel.apache.org 网站,但到目前为止,无法找到使用参数的示例“命名查询”示例 - 就像我的,上面

例如,https://camel.apache.org/components/latest/jpa-component.html)

【问题讨论】:

标签: spring-boot apache-camel java-11 spring-camel


【解决方案1】:

您指定了选项updateTs,这不是 JPA 组件的已知选项。

【讨论】:

  • 嗨克劳斯 - “updateTs”是实体类中的一个属性,它对应于“ThingTable”表中的一列(我也在命名查询中将它用作变量名:“SELECT e FROM ThingTable e WHERE e.updateTs > :updateTs")。 --我的语法不正确吗?谢谢
  • ...为了进一步澄清,我认为在 process() 方法中, [&updateTs='" + startZDT.format(formatter)] 正在为参数分配一个值 - ":updateTs " 在命名查询的 where 子句中 - 即 [WHERE e.updateTs > :updateTs]...
猜你喜欢
  • 1970-01-01
  • 2021-03-12
  • 1970-01-01
  • 1970-01-01
  • 2016-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多