Uploaded image for project: 'Spring XD'
  1. Spring XD
  2. XD-2581

JDBC sink doesn't deserialize JSON types correctly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: To Do
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Waiting for Triage
    • Component/s: None
    • Labels:
      None
    • Story Points:
      2
    • Rank (Obsolete):
      9223372036854775807

      Description

      Expected

      1. Create MYTABLE table with DATE or TIMESTAMP column MYTIME
      2. Create a stream ending with

      ... | object-to-json | jdbc --tableName=MYTABLE ...

      3. Send a message with payload being a Java object that has a property myTime of type java.util.Date
      4. Message payload is inserted into MYTABLE table, date is correctly stored in MYTIME column.

      Actual

      4. Exception is thrown from JDBC sink which attempts to bind a long into MYTIME column.

      Root cause

      JDBC sink uses org.springframework.xd.jdbc.JdbcMessagePayloadTransformer class to deserialize JSON payload into Map which will later be used to bind parameters into java.sql.PreparedStatement.

      Unfortunately JdbcMessagePayloadTransformer, and MessageTransformingHandler which is calling it, doesn't respect json__TypeId__ message header so information about Java types is lost. Other Spring XD components serialize java.util.Date as Unix timestamp e.g. object-to-json transformer. JDBC sink will deserialize the date as java.lang.Long and later attempt to bind incorrect type to query parameter.

      In case of GemFire XD following exception will be thrown during query parameter binding phase:

      com.pivotal.gemfirexd.internal.shared.common.sanity.AssertFailure: ASSERT FAILED Number of parameters expected for message id 22005 (3) does not match number of arguments received (2)
      	at com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager.ASSERT(SanityManager.java:239)
      	at com.pivotal.gemfirexd.internal.shared.common.i18n.MessageUtil.formatMessage(MessageUtil.java:245)
      	at com.pivotal.gemfirexd.internal.shared.common.i18n.MessageUtil.getCompleteMessage(MessageUtil.java:151)
      	at com.pivotal.gemfirexd.internal.shared.common.i18n.MessageUtil.getCompleteMessage(MessageUtil.java:191)
      	at com.pivotal.gemfirexd.internal.shared.common.i18n.MessageUtil.getCompleteMessage(MessageUtil.java:107)
      	at com.pivotal.gemfirexd.internal.client.am.SqlException.<init>(SqlException.java:184)
      	at com.pivotal.gemfirexd.internal.client.am.PreparedStatement$PossibleTypes.throw22005Exception(PreparedStatement.java:4007)
      	at com.pivotal.gemfirexd.internal.client.am.PreparedStatement.setLong(PreparedStatement.java:843)
      	at com.pivotal.gemfirexd.internal.client.am.PreparedStatement.setObject(PreparedStatement.java:1688)
      	at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:402)
      	at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:235)
      	at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:150)
      	at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:300)
      	at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:252)
      	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:638)
      	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
      	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:933)
      	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:313)
      	at org.springframework.integration.jdbc.JdbcMessageHandler.executeUpdateQuery(JdbcMessageHandler.java:130)
      	at org.springframework.integration.jdbc.JdbcMessageHandler.handleMessageInternal(JdbcMessageHandler.java:112)
      	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
      	... 372 more
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              kdowbecki Karol Dowbecki
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: