java.sql.SQLException: Numeric Overflow When Connecting to Oracle using MyBatis

Im using mybatis framework, and it was working very nice untuil today ive found a very weird error. A very weird error, because im only doing select queries and not insert anything.

This is the complete stacktrace,

Cause: java.sql.SQLException: Numeric Overflow
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy190.selectByExample(Unknown Source)
Caused by: java.sql.SQLException: Numeric Overflow
	at oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4381)
	at oracle.jdbc.driver.NumberCommonAccessor.getShort(NumberCommonAccessor.java:353)
	at oracle.jdbc.driver.OracleResultSetImpl.getShort(OracleResultSetImpl.java:1118)
	at oracle.jdbc.driver.OracleResultSet.getShort(OracleResultSet.java:418)
	at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getShort(DelegatingResultSet.java:272)
	at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getShort(DelegatingResultSet.java:272)
	at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

This is my java bean,

public class TblInvalid implements Serializable {
    private short id;

    private String attribute7;

    // other setter and getter
}

My Oracle DDL looks like this,

CREATE TABLE TBL_INVALID
    (
        ID NUMBER,
        ATTRIBUTE7 VARCHAR2(255)
 )

The workaround is actually so simple, changing from Short into BigDecimal makes the problem goes away.

public class TblInvalid implements Serializable {
    private BigDecimal id;

    private String attribute7;

    // other setter and getter
}
Google+

No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked


:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)