|
[
Permlink
| « Hide
]
Henri Yandell added a comment - 16/Oct/07 03:52 PM
What part of the DbUtils API are you using?
Hi Henri
I update the content on JIRA, please check it out. Matt I've run into the same issue. My beanClass that I pass to this method has fields that are Long types when database fields are NUMBER NULLABLE in Oracle 9i using ojdbc14.jar jdbc driver.
public static Object doBeanQuery(String sql, Class beanClass, DbConnectionPool dbConnectionPool) { Thanks I've traced down what I believe is happening,
in class BeanProcessor protected Object processColumn(ResultSet rs, int index, Class propType) {
....
} else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { The rs.getLong(index) returns zero when the column is null. This is really returning a primative type long not Long, so it has to have a value and can't be null. Per the Java Documentation getLong long getLong(int columnIndex) Retrieves the value of the designated column in the current row of this ResultSet object as a long in the Java programming language. Parameters: Does anyone have any ideas on how it worked before? By looking through the subversion repository, I found that in DbUtils 1.0 only rs.getObject(index) was used, which effectively returned <code>null</code> when the value is SQL NULL.
The problem is that some database, when using getObject, will return a BigInteger instead of a Long (for example), so I assume that this was the (a) reason for which the method getLong has been used instead of getObject. A simple fix could be: Object res = new Long(rs.getLong(index)); (And generalize the given code for all the different types in the method processColumn). I will provide the corresponding patch this evening (cannot use svn:checkout at my current place, only have a web browser). Julien I disagree the the classification of this as an 'Improvement' issue (sorry if this is just poor naming by JIRA, I'm not too familiar...).
The comments clearly state that null will be returned if the column value was null. This is a bug, either in comments or the code. Looked at the patch that Julien submitted in January. The problem with the fix he proposes is that null is returned even if the bean property is a primitive type. The fix I propose is less code, and only returns null if the bean property is an Object type. Fix to BeanProcessor which fixes processColumn.
Returns null if the bean property is an Object type, and the resultSet returns null. First, I agree with Brandon, my patch would definitely return null even if the bean property is a primitive type, so my patch would break some code later.
I will submit a corrected version of mine, which will not return null when the bean property is a primitive type. Then, I looked at Brandon patch: A slightly modified version of my original patch, which check if the bean property is not a primitive type before returning null.
Fixed using Brandon's patch in "bugfixing" branch revision 742701.
svn ci -m "Merging in Dab Fabulich's work on https://svn.apache.org/repos/asf/commons/sandbox/dbutils/bugfixing
Sending pom.xml |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||