Commons DbUtils
  1. Commons DbUtils
  2. DBUTILS-42

Object with Long or Decimal got initial zero value while database field is null

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Labels:
      None
    • Environment:

      JDK 5.0, MSSQL 2000

      Description

      While I use dbutil1.1, I got a big different implementation betweeb 1.0 and 1.1.
      Given a Java object, it has a property with Long data type; mapping to database, its table field datatype is bigint.
      If it has a record and its value is null.

      In 1.0 implementation, if I load entity, then we can see the property in Java object is also null.
      But in 1.1 implementation, the Java object will got a Long object with 0 inside.

      This behavior change does big impact if I upgrade from 1.0 to 1.1. It might make application logic fail because origional null status now become a Long(0) value to map to null value in database.

      I suggest to change it back. If null value in database, then mapped Java object should be null as well, not new a Long(0) to be a initial value.

      Below is the code snapshot I used to execute query, and I use jTDS 1.2 as JDBC driver

      public List<E> executePreparedQuery(String sql, Object[] params, Class clazz) throws SQLException {
          
          Connection cnct = getConnection();
          QueryRunner qRunner = new QueryRunner();
          ResultSetHandler rsHandler = new BeanListHandler(clazz);
          List<E> entities = null;
          try {
          	convertDateIn(params);
          	entities = (List<E>) qRunner.query(cnct, sql, params, rsHandler);
          }
          catch (SQLException e) {
          	e.printStackTrace();
          	throw e;
          }
          finally {
          	closeConnection();
          }
          return entities;
        }
      

      Hope this helps.

      1. BeanProcessor.diff
        2 kB
        Julien Aymé
      2. BeanProcessorAlternativePatch.diff
        0.5 kB
        Brandon Atkinson
      3. BeanProcessor-fixed.diff
        2 kB
        Julien Aymé

        Activity

        Dan Fabulich made changes -
        Assignee Dan Fabulich [ dfabulich ]
        Henri Yandell made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Henri Yandell made changes -
        Fix Version/s 1.2 [ 12312139 ]
        Julien Aymé made changes -
        Attachment BeanProcessor-fixed.diff [ 12392951 ]
        Brandon Atkinson made changes -
        Attachment BeanProcessorAlternativePatch.diff [ 12392930 ]
        Dennis Lundberg made changes -
        Description While I use dbutil1.1, I got a big different implementation betweeb 1.0 and 1.1.
        Given a Java object, it has a property with Long data type; mapping to database, its table field datatype is bigint.
        If it has a record and its value is null.

        In 1.0 implementation, if I load entity, then we can see the property in Java object is also null.
        But in 1.1 implementation, the Java object will got a Long object with 0 inside.

        This behavior change does big impact if I upgrade from 1.0 to 1.1. It might make application logic fail because origional null status now become a Long(0) value to map to null value in database.

        I suggest to change it back. If null value in database, then mapped Java object should be null as well, not new a Long(0) to be a initial value.

        Below is the code snapshot I used to execute query, and I use jTDS 1.2 as JDBC driver

        public List<E> executePreparedQuery(String sql, Object[] params, Class clazz) throws SQLException {
            
            Connection cnct = getConnection();
            QueryRunner qRunner = new QueryRunner();
            ResultSetHandler rsHandler = new BeanListHandler(clazz);
            List<E> entities = null;
            try {
             convertDateIn(params);
             entities = (List<E>) qRunner.query(cnct, sql, params, rsHandler);
            }
            catch (SQLException e) {
             e.printStackTrace();
             throw e;
            }
            finally {
             closeConnection();
            }
            return entities;
          }

        Hope this helps.
        While I use dbutil1.1, I got a big different implementation betweeb 1.0 and 1.1.
        Given a Java object, it has a property with Long data type; mapping to database, its table field datatype is bigint.
        If it has a record and its value is null.

        In 1.0 implementation, if I load entity, then we can see the property in Java object is also null.
        But in 1.1 implementation, the Java object will got a Long object with 0 inside.

        This behavior change does big impact if I upgrade from 1.0 to 1.1. It might make application logic fail because origional null status now become a Long(0) value to map to null value in database.

        I suggest to change it back. If null value in database, then mapped Java object should be null as well, not new a Long(0) to be a initial value.

        Below is the code snapshot I used to execute query, and I use jTDS 1.2 as JDBC driver

        {code}
        public List<E> executePreparedQuery(String sql, Object[] params, Class clazz) throws SQLException {
            
            Connection cnct = getConnection();
            QueryRunner qRunner = new QueryRunner();
            ResultSetHandler rsHandler = new BeanListHandler(clazz);
            List<E> entities = null;
            try {
             convertDateIn(params);
             entities = (List<E>) qRunner.query(cnct, sql, params, rsHandler);
            }
            catch (SQLException e) {
             e.printStackTrace();
             throw e;
            }
            finally {
             closeConnection();
            }
            return entities;
          }
        {code}

        Hope this helps.
        Julien Aymé made changes -
        Attachment BeanProcessor.diff [ 12374530 ]
        Matt Jiang made changes -
        Field Original Value New Value
        Description While I use dbutil1.1, I got a big different implementation betweeb 1.0 and 1.1.
        Given a Java object, it has a property with Long data type; mapping to database, its table field datatype is bigint.
        If it has a record and its value is null.

        In 1.0 implementation, if I load entity, then we can see the property in Java object is also null.
        But in 1.1 implementation, the Java object will got a Long object with 0 inside.

        This behavior change does big impact if I upgrade from 1.0 to 1.1. It might make application logic fail because origional null status now become a Long(0) value to map to null value in database.

        I suggest to change it back. If null value in database, then mapped Java object should be null as well, not new a Long(0) to be a initial value.
        While I use dbutil1.1, I got a big different implementation betweeb 1.0 and 1.1.
        Given a Java object, it has a property with Long data type; mapping to database, its table field datatype is bigint.
        If it has a record and its value is null.

        In 1.0 implementation, if I load entity, then we can see the property in Java object is also null.
        But in 1.1 implementation, the Java object will got a Long object with 0 inside.

        This behavior change does big impact if I upgrade from 1.0 to 1.1. It might make application logic fail because origional null status now become a Long(0) value to map to null value in database.

        I suggest to change it back. If null value in database, then mapped Java object should be null as well, not new a Long(0) to be a initial value.

        Below is the code snapshot I used to execute query, and I use jTDS 1.2 as JDBC driver

        public List<E> executePreparedQuery(String sql, Object[] params, Class clazz) throws SQLException {
            
            Connection cnct = getConnection();
            QueryRunner qRunner = new QueryRunner();
            ResultSetHandler rsHandler = new BeanListHandler(clazz);
            List<E> entities = null;
            try {
             convertDateIn(params);
             entities = (List<E>) qRunner.query(cnct, sql, params, rsHandler);
            }
            catch (SQLException e) {
             e.printStackTrace();
             throw e;
            }
            finally {
             closeConnection();
            }
            return entities;
          }

        Hope this helps.
        Matt Jiang created issue -

          People

          • Assignee:
            Dan Fabulich
            Reporter:
            Matt Jiang
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development