Wednesday, 20 March 2013

A system with a bad design is falling apart

Production log files are throwing this exception
ERROR [org.hibernate.util.JDBCExceptionReporter] '2.147504819E9' in column '1' is outside valid range for the datatype INTEGER

I got that exception when some code was trying to get an "int(11) unsigned" and put it into a Java's Integer

At the first look this exception seems a database problem but it is not, it is thrown by the MySql JDBC Driver

if (this.jdbcCompliantTruncationForReads) {
    if (valueAsDouble < Integer.MIN_VALUE
     || valueAsDouble > Integer.MAX_VALUE) {
         throwRangeException(String.valueOf(valueAsDouble), 
             columnIndex, Types.INTEGER)
    }
}
At the end, all calls to getInt have to be changed to getLong.