Tuesday, January 17, 2012

Dev environment returning String for generated key Object type

I have a bit of strange issue when using Spring JdbcTemplate with the development environment. When using the mysql driver directly, the auto-generated key returned on an insert passes this test (from GeneratedKeyHolder:73):

Object key = keyIter.next();

if (!(key instanceof Number)) {
    throw new DataRetrievalFailureException(
    "The generated key is not of a supported numeric type. " +
    "Unable to cast [" + (key != null ? key.getClass().getName() : null) +
    "] to [" + Number.class.getName() + "]");
}

but, when using the AppEngineDriver (1.6.1) it is returned as a string, so this check fails. I tried setting useInformationSchema=true in the rdms.url, but it seems to have no affect. The google version of ResultSetMetaData is responsible for setting the type, so I am curious why this functions differently then the standard mysql implementation, and how I can fix it without having to override Spring's GeneratedKeyHolder?

I have not tried this in production.

Regards,
Mark

No comments:

Post a Comment