当前位置: 首页 > 知识库问答 >
问题:

未看到Camel JPA查询参数

陆昕
2023-03-14

我目前在让Camel查看当前代码的JPA查询参数方面遇到了问题。我已经测试过注册表可以访问我的映射中的参数,但是我在民意测验中的jpaendpoint说它找不到我的参数。

版本:

 JBoss Fuse: 6.2.1.redhat-084
 Camel: 6.2.1.redhat-084
 Hibernate: 4.2.20.Final-redhat-1
 Hibernate jpa 2.0 API: 1.0.1.Final

骆驼路线:

    from("direct:routeUpdates").routeId("RouteUpdates")
        .log(LoggingLevel.DEBUG, "${body}")
        .beanRef("ParameterManager", "setupQueryParameters").id("DetermineNamedQueryParameters")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                Registry registry = exchange.getContext().getRegistry();
                Map<String, Object> map = registry.lookupByNameAndType("params", Map.class);
                System.out.println("driverId: " + map.get("driverId"));
                System.out.println("statusDate: " + map.get("statusDate"));
            }
        })
        .pollEnrich("jpa:" + RouteEntity.class.getName() + "?consumeDelete=false&delay=3000&consumeLockEntity=false&consumer.namedQuery=findRouteByDriverIdAndDate&consumer.parameters=#params", new RouteStatusAggregationStrategy()).id("EnrichWithPreviousRouteEntityData")
        .to("jpa:" + RouteEntity.class.getName() + "?usePersist=false&flushOnSend=true&joinTransaction=true").id("PersistRouteEntity");

Spring上下文:

<bean id="PackageCarStatusRoute" class="com.ups.ops.cipe.internal.route.PackageCarStatusRoute">
</bean>

<bean id="ParameterManager" class="com.ups.ops.cipe.internal.parameter.RouteEntityNamedQueryParameterManager">
    <property name="params" ref="params" />
</bean>

<util:map id="params" key-type="java.lang.String">
    <entry key="driverId" value="0049124"/>
    <entry key="statusDate" value="Wed Apr 13 21:02:17 EDT 2016"/>
</util:map>

JPA实体:

@Entity
@IdClass(RouteEntityId.class)
@Table(name = "RouteStatus")
@NamedQuery(name = "findRouteByDriverIdAndDate", query = "SELECT r FROM RouteEntity r WHERE r.driverId = :driverId AND r.statusDate = :statusDate")
public class RouteEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "DriverId", updatable = false, nullable = false, length = 20)
    private String driverId;

    @Id
    @Temporal(TemporalType.DATE)
    @Column(name = "StatusDate", updatable = false, nullable = false)
    private Date statusDate;

    @Column(name = "DriverName", length = 5-)
    private String driverName;

    //removed setters getters and other variables for brevity
}

日志:

driverId: 0049124
statusDate: Wed Apr 13 21:02:17 EDT 2016
2016-04-13 17:02:22,057 [ity.RouteEntity] WARN  JpaConsumer                    - Consumer Consumer[jpa://com.ups.ops.cipe.external.route.entity.RouteEntity?consumeDelete=false&consumeLockEntity=falseconsumer.namedQuery%3DfindRouteByDriverIdAndDate&consumer.parameters=%23params&delay=3000] failed polling endpoint: Endpoint[jpa://com.ups.ops.cipe.external.route.entity.RouteEntity?consumeDelete=false&consumeLockEntity=falseconsumer.namedQuery%3DfindRouteByDriverIdAndDate&consumer.parameters=%23params&delay=3000]. Will try again at next poll. Caused by: [java.lang.IllegalArgumentException - org.hibernate.QueryParameterException: could not locate named parameter [driverId]]
java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [driverId]
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:377)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:74)
    at org.apache.camel.component.jpa.JpaConsumer.configureParameters(JpaConsumer.java:488)
    at org.apache.camel.component.jpa.JpaConsumer$1.doInTransaction(JpaConsumer.java:101)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)
    at org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:92)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.QueryParameterException: could not locate named parameter [driverId]
    at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:100)
    at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:106)
    at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:466)
    at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:436)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:371)
    ... 14 more

共有1个答案

公冶浩慨
2023-03-14

好吧,我知道了。长话短说是为了确保我不会弄乱我的spring模式位置标记。我有:

xmlns:util="http://www.springframework.org/schema/util"

我忘记将其添加到架构位置:

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd

对于任何有相同问题的人来说,春末收割台都是这样的:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
 类似资料:
  • 我有一个问题: 我已经做了: 作曲家更新

  • 我正在尝试从一个节点传递一个API,其中字符包含'&'(例如:AT&T),在url查询参数中,我没有得到与AT&T相关联的值,而是它返回的空字符串。有人知道这事吗? http://localhost:3000/account?accountName=AT&T []

  • 我有一个基本的rest控制器,可以获取参数。 如果查询字符串包含我没有定义的参数,我如何拒绝连接? 当前,在调用此url时,只使用id执行该方法,而忽略未知的参数。一般来说,这很好,但我如何验证它们,以防返回HTTP状态码?

  • 问题内容: 我正在尝试测试将参数传递给sql.DB.Query方法的行为(使用database / sql包和github.com/lib/pq上的PostgreSQL驱动程序)。处理原始查询字符串以查看如何插入参数后,是否有任何方法可以获取原始查询字符串?例如,我正在考虑编写一个准备好的查询,然后检查结果语句。有任何想法吗?谢谢! 问题答案: 它看起来不像在查询本身中插入参数。它发送查询,然后等

  • 查询创建工具及查询编辑器都支持在查询文本使用参数。你可以设置查询参数来在每次运行查询时添加变量值。参数应作为一个识别符以 $ 开头,[ ] 括住,例如 [$任何名]。 运行查询及 输入参数 对话框提供你输入想要搜索的数据。

  • 查询支持在查询文本内使用参数。你可以设置查询参数,于每次运行查询时添加变量值。参数是一个以 $ 开头以及用 [ ] 括住的标识符,例如:[$任何名]。 运行查询时,你可以在“输入参数”对话框输入你想要搜索的数据。如勾选“原始模式”选项,将不会在传递输入值到查询时添加引号。