Skip to content

JDBC conversion exception for enum types on MySQL [SPR-12174] #16788

@spring-projects-issues

Description

@spring-projects-issues

cemo koc opened SPR-12174 and commented

I have updated our codebase to spring 4.1 and had some problems.

I am working with MySQL 5.6 and latest driver (5.1.32) and JDK8. The block below from JdbcUtils is throwing an exception at line return rs.getObject(index, requiredType);

if (getObjectWithTypeAvailable) {
     try {
              return rs.getObject(index, requiredType);
     }
     catch (SQLFeatureNotSupportedException ex) {
              logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex);
     }
     catch (AbstractMethodError err) {
              logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err);
     }
}
// Fall back to getObject without type specification...
return getResultSetValue(rs, index);

I have also evaluated last statement which is working as expected.

return getResultSetValue(rs, index);

Here is the details:


ERROR [2014-09-10 12:44:55,993] com.clovify.lyso.guava.OptionalExtractorFactory: guava extractor expcetion: 
! java.sql.SQLException: Conversion not supported for type xxx.enums.Gender
! at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094) ~[mysql-connector-java-5.1.31.jar:na]
! at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997) ~[mysql-connector-java-5.1.31.jar:na]
! at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983) ~[mysql-connector-java-5.1.31.jar:na]
! at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928) ~[mysql-connector-java-5.1.31.jar:na]
! at com.mysql.jdbc.ResultSetImpl.getObject(ResultSetImpl.java:5121) ~[mysql-connector-java-5.1.31.jar:na]
! at com.mysql.jdbc.JDBC4ResultSet.getObject(JDBC4ResultSet.java:542) ~[mysql-connector-java-5.1.31.jar:na]
! at org.springframework.jdbc.support.JdbcUtils.getResultSetValue(JdbcUtils.java:197) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.BeanPropertyRowMapper.getColumnValue(BeanPropertyRowMapper.java:311) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.BeanPropertyRowMapper.mapRow(BeanPropertyRowMapper.java:249) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:705) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:641) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! ... 69 common frames omitted
! Causing: org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [SELECT * FROM USER WHERE EMAIL = ?]; Conversion not supported for type xxx.enums.Gender; nested exception is java.sql.SQLException: Conversion not supported for type xxx.enums.Gender
! at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:657) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:692) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:719) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:769) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]
! at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:211) ~[spring-jdbc-4.1.0.RELEASE.jar:4.1.0.RELEASE]

Is there any information I can provide?


Affects: 4.1 GA

Issue Links:

Referenced from: commits 8922da3

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions