Apache Camel sql-component无法转换为内部表示

时间:2019-01-25 12:20:48

标签: apache-camel camel-sql

当我使用sql-compenent可以从数据库中检索记录时,Map<String,Object>可以。

<to uri="sql-clsivtrk:{{clsiv_tracker_config_se}}?outputType=SelectOne" />

但是,当我这样定义outputClass时:

<to uri="sql-clsivtrk:{{clsiv_tracker_config_se}}?outputType=SelectOne&amp;outputClass=br.com.rwit.clsi.m2m.rs.model.TrackerConfig" />

我收到错误java.sql.SQLException: Fail to convert to internal representation

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route9            ] [route9            ] [servlet:/events/config?httpMethodRestrict=PUT                                 ] [        93]
[route9            ] [to39              ] [direct:save-config                                                            ] [         0]
[tracker-configurat] [convertBodyTo4    ] [convertBodyTo[java.lang.String]                                               ] [         0]
[tracker-configurat] [unmarshal4        ] [unmarshal[ref:trackerConfigJsonList]                                          ] [         2]
[tracker-configurat] [log4              ] [log                                                                           ] [         1]
[tracker-configurat] [split3            ] [split[simple{${body}}]                                                        ] [         6]
[tracker-configurat] [to6               ] [sql-tracker:{{tracker_config_se}}?outputType=SelectOne&outputClass=br.com.acme] [        83]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException; SQL state [99999]; error code [17059]; Fail to convert to internal representation; nested exception is java.sql.SQLException: Fail to convert to internal representation
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:620)
    at org.apache.camel.component.sql.SqlProducer.process(SqlProducer.java:116)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
Caused by: java.sql.SQLException: Fail to convert to internal representation
    at oracle.jdbc.driver.CharCommonAccessor.getBoolean(CharCommonAccessor.java:185)
    at oracle.jdbc.driver.T4CVarcharAccessor.getBoolean(T4CVarcharAccessor.java:794)
    at oracle.jdbc.driver.OracleResultSetImpl.getBoolean(OracleResultSetImpl.java:640)
    at com.sun.gjc.spi.base.ResultSetWrapper.getBoolean(ResultSetWrapper.java:169)
    at org.springframework.jdbc.support.JdbcUtils.getResultSetValue(JdbcUtils.java:148)
    at org.springframework.jdbc.core.BeanPropertyRowMapper.getColumnValue(BeanPropertyRowMapper.java:377)
    at org.springframework.jdbc.core.BeanPropertyRowMapper.mapRow(BeanPropertyRowMapper.java:298)
    at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
    at org.apache.camel.component.sql.DefaultSqlEndpoint.queryForObject(DefaultSqlEndpoint.java:488)
    at org.apache.camel.component.sql]]

我的outputType

import java.util.Calendar;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;


import java.util.Calendar;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;

public class TrackerConfig
{
    private static final String HOST1                   = "http://locahost/";
    private static final String HOST2                   = "http://localhost/";
    private static final String CONTEXT                 = "my-ctx/";
    private static final String API                     = "api/";

    private static final int    DEFAULT_INTERVAL_TRANSM = 60;
    private static final int    DEFAUL_INTERVAL_CAPT    = 30;
    private static final int    DEFAUL_BATCHSIZE        = 100;
    private static final int    DEFAUL_RENEW_CONF       = 3600;

    private String              deviceImei1;
    private String              deviceImei2;
    private String              phoneNumber;
    private String              deviceSO;
    private String              deviceModel;
    private String              deviceSNumber;
    private String              myIp;

    private String              host1;
    private String              host2;
    private String              context;
    private String              api;

    private Number              intervalOftransmission;
    private Number              intervalOfCapture;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private Date                captureBegin;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private Date                captureFinal;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private Date                transmissionBegin;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private Date                transmissionFinal;
    private Double              minDistance;
    private Double              maxDistance;
    private Number              intervalOfRenewConfig;
    private String              levelConfig;

    private String              deprecated;
    private String              route;
    private String              version;
    private Double              accuracy;
    private Number              batchSize;

    public TrackerConfig()
    {
        this.intervalOftransmission = DEFAULT_INTERVAL_TRANSM;
        this.intervalOfCapture = DEFAUL_INTERVAL_CAPT;
        this.batchSize = DEFAUL_BATCHSIZE;
        this.intervalOfRenewConfig = DEFAUL_RENEW_CONF;
        this.captureBegin = newTime(7, 0, 0);
        this.captureFinal = newTime(18, 0, 0);
        this.transmissionBegin = newTime(4, 6, 0);
        this.transmissionFinal = newTime(23, 59, 59);
        this.minDistance = 10D;
        this.maxDistance = 10001D;
        this.host1 = HOST1;
        this.host2 = HOST2;
        this.context = CONTEXT;
        this.api = API;
        this.levelConfig = "INFO";
    }
    // ommit getters and setters
}

使用2.22.2

1 个答案:

答案 0 :(得分:1)

您可以显示您的outputClass吗?

请参见https://github.com/apache/camel/blob/camel-2.22.x/components/camel-sql/src/main/docs/sql-component.adoc

outputType下显示:

  

将使用者或生产者的输出作为Select List作为Map列表,   或通过以下方式将SelectOne作为单个Java对象:a)如果   查询只有一个列,则该JDBC列对象是   回到。 (例如SELECT COUNT()FROM PROJECT将返回Long   宾语。 b)如果查询有多个列,则它将返回   该结果的地图。 c)如果设置了outputClass,则它将   通过调用所有,将查询结果转换为Java bean对象   与列名称匹配的设置器。它将假定您的班级有一个   用于创建实例的默认构造函数。 d)如果查询结果   在多行中,它将引发一个非唯一的结果异常。

应该做的一件事情是,列名应该与设置器匹配,并且应该存在一个默认的构造函数。是这样吗?