Issue Details (XML | Word | Printable)

Key: DBUTILS-42
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dan Fabulich
Reporter: Matt Jiang
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

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

Created: 16/Oct/07 01:14 PM   Updated: 07/Mar/09 06:09 AM
Return to search
Component/s: None
Affects Version/s: 1.1
Fix Version/s: 1.2

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works BeanProcessor-fixed.diff 2008-10-28 09:42 PM Julien Aymé 2 kB
File Licensed for inclusion in ASF works BeanProcessor.diff 2008-02-01 07:40 AM Julien Aymé 2 kB
File Licensed for inclusion in ASF works BeanProcessorAlternativePatch.diff 2008-10-28 01:43 PM Brandon Atkinson 0.5 kB
Environment: JDK 5.0, MSSQL 2000

Resolution Date: 25/Feb/09 10:02 AM


 Description  « Hide
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.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #742701 Mon Feb 09 19:44:18 UTC 2009 dfabulich [DBUTILS-42] Object with Long or Decimal got initial zero value while database field is null
Submitted by: Brandon Atkinson
Files Changed
MODIFY /commons/sandbox/dbutils/bugfixing/src/java/org/apache/commons/dbutils/BeanProcessor.java

Repository Revision Date User Message
ASF #747724 Wed Feb 25 10:01:31 UTC 2009 bayard Merging in Dab Fabulich's work on https://svn.apache.org/repos/asf/commons/sandbox/dbutils/bugfixing from -r741987:747723. Resolving DBUTILS-34 - DBUTILS-37 - DBUTILS-29 - DBUTILS-14 - DBUTILS-31 - DBUTILS-39 - DBUTILS-41 - DBUTILS-44 - DBUTILS-33 - DBUTILS-42 - DBUTILS-40
Files Changed
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/BasicRowProcessor.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/BeanProcessor.java
ADD /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java (from /commons/sandbox/dbutils/bugfixing/src/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java)
MODIFY /commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BaseTestCase.java
MODIFY /commons/proper/dbutils/trunk/pom.xml
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
DEL /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java
ADD /commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/QueryRunnerTest.java (from /commons/sandbox/dbutils/bugfixing/src/test/org/apache/commons/dbutils/QueryRunnerTest.java)
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
MODIFY /commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/QueryRunner.java