Change the logic to get the Java class from ResultSetMetadata
--------------------------------------------------------------
Key: CAY-672
URL: http://issues.apache.org/cayenne/browse/CAY-672
Project: Cayenne
Type: Improvement
Components: Cayenne Core Library
Versions: 1.2 [STABLE], 3.0, 2.0 [STABLE]
Reporter: Andrus Adamchik
Assigned to: Andrus Adamchik
Fix For: 3.0
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();
}
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/cayenne/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira
This archive was generated by hypermail 2.0.0 : Thu Sep 28 2006 - 11:35:46 EDT