Camel JPA查询参数未见

时间:2016-04-13 21:24:27

标签: spring jpa apache-camel

我目前在让Camel查看当前代码的JPA查询参数时遇到问题。我已经测试过注册表可以访问我的地图中的参数,但是pollenrich中的jpa端点说它找不到我的参数。

版本:

 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 Context:

             

<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 个答案:

答案 0 :(得分:1)

好的想通了。长话短说是确保我不会弄乱我的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">