Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.2 branch, 2.0 branch, 3.0
-
None
Description
See this problem here:
http://objectstyle.org/cayenne/lists/cayenne-user/2006/09/0142.html
It occurs because ColumnDescriptor incorrectly maps the Java type of a result set column via "TypesMapping.getJavaBySqlType":
Index: /Users/andrus/work/cayenne/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java
===================================================================
— /Users/andrus/work/cayenne/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java (revision 449507)
+++ /Users/andrus/work/cayenne/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java (working copy)
@@ -136,9 +136,10 @@
this.qualifiedColumnName = name;
this.label = name;
this.jdbcType = metaData.getColumnType(position);
- this.javaClass = getDefaultJavaClass(
- metaData.getColumnDisplaySize(position),
- metaData.getScale(position));
+ this.javaClass = metaData.getColumnClassName(position);
+// this.javaClass = getDefaultJavaClass(
+// metaData.getColumnDisplaySize(position),
+// metaData.getScale(position));
}
/**
Replacing it with ResultSetMetadata.getColumnClassName() produces correct result, however this may break some DataRow assumptions, so probably adding this fix in 1.2 is not a good idea (although all current unit tests pass with the fix, so this may not be that bad)
Here is a unit test that demonstrates it, using "INT UNSIGNED" MySQL type:
public void testLong() throws Exception
{ context.performGenericQuery(new SQLTemplate( LongEntity.class, "DROP TABLE LONG_ENTITY")); context .performGenericQuery(new SQLTemplate( LongEntity.class, "CREATE TABLE LONG_ENTITY " + "(ID INT NOT NULL, LONG_FIELD INT UNSIGNED NULL, PRIMARY KEY (ID))")); LongEntity test = (LongEntity) context.newObject(LongEntity.class); Long i = new Long(Integer.MAX_VALUE + 10l); test.setLongField(i); context.commitChanges(); SelectQuery q = new SelectQuery(LongEntity.class); LongEntity testRead = (LongEntity) context.performQuery(q).get(0); assertNotNull(testRead.getLongField()); assertEquals(i, testRead.getLongField()); SQLTemplate q1 = new SQLTemplate(LongEntity.class, "select * from LONG_ENTITY"); q1.setFetchingDataRows(true); DataRow row = (DataRow) context.performQuery(q1).get(0); assertEquals(i, row.get("LONG_FIELD")); test.setLongField(null); context.commitChanges(); }