微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我在 Processor.process() 方法中使用的“命名查询”不起作用? -我该如何修复它?

如何解决为什么我在 Processor.process() 方法中使用的“命名查询”不起作用? -我该如何修复它?

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

描述错误的堆栈跟踪片段:

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

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。