[JBoss-dev] Problem with CHAR, CMP2.0 and the Firebird driver.
Hi, (Please note that this problem could easily be avoided by using other types. But maybe a small change in the CMP engine and/or the Firebird driver would be better.) I'm using JBoss from CVS about a week old, and firebird-jca-jdbc-driver 1.0-beta-1. In my db, I have a column, defined as SEX CHAR and I have CMP2.0 accessors for it in my bean Character getSex(); void setSex(Character sex); My problems start when I create an instance of my bean This provokes an exception in the Firebird driver: org.firebirdsql.jdbc.TypeConvertionException: Error converting to object. at org.firebirdsql.jdbc.FBField.setObject(FBField.java:601) at org.firebirdsql.jdbc.FBPreparedStatement.setObject(FBPreparedStatement.java:212) at org.firebirdsql.jdbc.FBPreparedStatement.setObject(FBPreparedStatement.java:382) at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.setParameter(JDBCUtil.java:249) at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setArgumentParameters(JDBCAbstractCMPFieldBridge.java:283) at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setInstanceParameters(JDBCAbstractCMPFieldBridge.java:262) at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(JDBCCreateEntityCommand.java:192) at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:131) at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:527) at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270) (Line numbers may be slightly offset by extra debug code I inserted.) At JDBCUtil.java:249, there is a call pm.setObject(index, value, jdbcType); When this exception occurs, I can se that value is of class java.lang.Character with the value 'M', and that jdbcType is CHAR. I'm not an JDBC expert, but it looks to me like throwing an exception in this case may actually not be a JDBC violation (JDBC has no standard mapping from Character to CHAR). However, it seems logical to call the driver this way, so a change to the FBField class in the Firebird driver to allow this would be nice, and also simple to do. And _if_ the Firebird driver already is JDBC-conformant on this issue, we should probably change the CMP2.0 engine so that such a call is not done. That shouldn't be hard to do either, in the JDBCUtil.setParameter() method. But before I do any of the above changes, I would like to hear your comments. Best Regards, Ole Husgaard --- This sf.net email is sponsored by:ThinkGeek Oh, it's good to be a geek. http://thinkgeek.com/sf ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] Problem with CHAR, CMP2.0 and the Firebird driver.
Dain Sundstrom wrote: If you change the jdbc-type (not the sql-type) to VARCHAR, it should work for you. If the parameter type is a Character and the jdbc-type is a VARCHAR, the parameter is converted into a string before setting, and converted back into a character on get. This code was added for databases that don't support char types such as Oracle. This change does not require that the database column type change. I guess you are talking about the change you made in JDBCUtil.coerceToSQLType(). Try it out and if it does work please update the Firebird type in the standardjbosscmp-jdbc.xml file. Letting the database column type be VARCHAR instead would probably work fine. Unfortunately my DB is pre-defined. I'm not a JDBC expert, but it looks to me like there is no (JDBC-standard-) problem with the Firebird driver, since JDBC has no standard mapping from java.lang.Character to CHAR. However, there is a mapping from java.lang.String to CHAR. My temporary workaround is similar to what you did with VARCHAR, only I do it each time, like changing JDBCUtil.coerceToSQLType() to say: } else if(value.getClass() == Character.class) instead of: } else if(value.getClass() == Character.class jdbcType == Types.VARCHAR) (The only difference being that I do this conversion in JDBCUtil.setParameter(), just before the call pm.setObject(index, value, jdbcType); With that change all my code runs fine, though I have not run the complete testsuite.) It looks to me like the CMP engine would be more JDBC-conformant, if it always converts a Character to a String before setting a field. Is there any case where setting a String wouldn't work when a Character would? If not, we might as well always coerce Character to String. Best Regards, Ole Husgaard. -dain Ole Husgaard wrote: Hi, (Please note that this problem could easily be avoided by using other types. But maybe a small change in the CMP engine and/or the Firebird driver would be better.) I'm using JBoss from CVS about a week old, and firebird-jca-jdbc-driver 1.0-beta-1. In my db, I have a column, defined as SEX CHAR and I have CMP2.0 accessors for it in my bean Character getSex(); void setSex(Character sex); My problems start when I create an instance of my bean This provokes an exception in the Firebird driver: org.firebirdsql.jdbc.TypeConvertionException: Error converting to object. at org.firebirdsql.jdbc.FBField.setObject(FBField.java:601) at org.firebirdsql.jdbc.FBPreparedStatement.setObject(FBPreparedStatement.java:212) at org.firebirdsql.jdbc.FBPreparedStatement.setObject(FBPreparedStatement.java:382) at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.setParameter(JDBCUtil.java:249) at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setArgumentParameters(JDBCAbstractCMPFieldBridge.java:283) at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setInstanceParameters(JDBCAbstractCMPFieldBridge.java:262) at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(JDBCCreateEntityCommand.java:192) at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:131) at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:527) at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270) (Line numbers may be slightly offset by extra debug code I inserted.) At JDBCUtil.java:249, there is a call pm.setObject(index, value, jdbcType); When this exception occurs, I can se that value is of class java.lang.Character with the value 'M', and that jdbcType is CHAR. I'm not an JDBC expert, but it looks to me like throwing an exception in this case may actually not be a JDBC violation (JDBC has no standard mapping from Character to CHAR). However, it seems logical to call the driver this way, so a change to the FBField class in the Firebird driver to allow this would be nice, and also simple to do. And _if_ the Firebird driver already is JDBC-conformant on this issue, we should probably change the CMP2.0 engine so that such a call is not done. That shouldn't be hard to do either, in the JDBCUtil.setParameter() method. But before I do any of the above changes, I would like to hear your comments. Best Regards, Ole Husgaard --- This sf.net email is sponsored by:ThinkGeek Oh, it's good to be a geek. http://thinkgeek.com/sf ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development -- Dain Sundstrom
Re: [JBoss-dev] Problem with CHAR, CMP2.0 and the Firebird driver.
Ole Husgaard wrote: Dain Sundstrom wrote: If you change the jdbc-type (not the sql-type) to VARCHAR, it should work for you. If the parameter type is a Character and the jdbc-type is a VARCHAR, the parameter is converted into a string before setting, and converted back into a character on get. This code was added for databases that don't support char types such as Oracle. This change does not require that the database column type change. I guess you are talking about the change you made in JDBCUtil.coerceToSQLType(). Yes. Try it out and if it does work please update the Firebird type in the standardjbosscmp-jdbc.xml file. Letting the database column type be VARCHAR instead would probably work fine. Unfortunately my DB is pre-defined. I'm not suggesting you change your database. The jdbc-type is just the type that the container tells the JDBC driver to use in order to set the type. It has nothing to do with the actual type of the column; the driver handled the type conversion. I'm not a JDBC expert, but it looks to me like there is no (JDBC-standard-) problem with the Firebird driver, since JDBC has no standard mapping from java.lang.Character to CHAR. However, there is a mapping from java.lang.String to CHAR. My temporary workaround is similar to what you did with VARCHAR, only I do it each time, like changing JDBCUtil.coerceToSQLType() to say: } else if(value.getClass() == Character.class) instead of: } else if(value.getClass() == Character.class jdbcType == Types.VARCHAR) (The only difference being that I do this conversion in JDBCUtil.setParameter(), just before the call pm.setObject(index, value, jdbcType); With that change all my code runs fine, though I have not run the complete testsuite.) If you change the jdbc-type (not your column type) to VARCHAR the code will work for you. It looks to me like the CMP engine would be more JDBC-conformant, if it always converts a Character to a String before setting a field. Not necessarily. Several databases are perfectly happy with Characters and CHAR jdbc-type. Is there any case where setting a String wouldn't work when a Character would? If not, we might as well always coerce Character to String. I don't know. Try changing the default jdbc-type for Firebird to VARCHAR and see if it works for Firebird. If it does then, we don't need to change any code. -- Dain Sundstrom Chief Architect JBossCMP JBoss Group, LLC --- This sf.net email is sponsored by:ThinkGeek Oh, it's good to be a geek. http://thinkgeek.com/sf ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
Re: [JBoss-dev] Problem with CHAR, CMP2.0 and the Firebird driver.
Dain Sundstrom wrote: Is there any case where setting a String wouldn't work when a Character would? If not, we might as well always coerce Character to String. I don't know. Try changing the default jdbc-type for Firebird to VARCHAR and see if it works for Firebird. If it does then, we don't need to change any code. This works fine for me. I'll commit that to CVS shortly. Thanks. Best Regards, Ole Husgaard. --- This sf.net email is sponsored by:ThinkGeek Oh, it's good to be a geek. http://thinkgeek.com/sf ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development