jpa入站通道适配器输出的问题

问题描述 投票:0回答:1
@Bean
public JpaPollingChannelAdapter reimStgResponseJpaInboundAdapter() {
    return Jpa
            .inboundAdapter(entityManager)
            .nativeQuery(responseQueryString)
            //.expectSingleResult(true)
            .get(); 
}

@Bean
public IntegrationFlow reimFeedbackHandle() {
    return IntegrationFlows
                    .from("reimFeedbackChannel")
                    .handle(msg -> {
                        try {
                            dctmHandler.handleReIMFeedback(msg);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }})
                    .get(); 
}

.expectSingleResult(true)返回异常,预计会有1个结果。

本机查询是String responseQueryString = "select * from RMS16DEV.TSC_IM_DOC_HEAD_TEMP where error_ind is not null";

来自入站适配器的消息是一个数组列表,我无法将其强制转换为正确的实体。 jpa入站适配器返回到通道的类型是什么?

public void handleReIMFeedback(Message<?> reimStgRowMsg) throws Exception {
    List<TSC_IM_DOC_HEAD_TEMP> list = (List<TSC_IM_DOC_HEAD_TEMP>) reimStgRowMsg.getPayload(); 
    System.out.println( (list.get(0)));
}

给我:

java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class java.util.List ([Ljava.lang.Object; and java.util.List are in module java.base of loader 'bootstrap')
at tesco.finance.gss.dctmreim.jpa.handlers.DctmHandlers.handleReIMFeedback(DctmHandlers.java:28)
`
spring-integration spring-integration-dsl
1个回答
0
投票

下面的代码修复了问题:

@Bean
public JpaPollingChannelAdapter reimStgResponseJpaInboundAdapter() {
    return Jpa
            .inboundAdapter(entityManager)
            .nativeQuery(responseQueryString)
            .expectSingleResult(true)
            .entityClass(TSC_IM_DOC_HEAD_TEMP.class)
            .get(); 
}
© www.soinside.com 2019 - 2024. All rights reserved.