Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0 Beta 3
-
None
-
Oracle 10, ojdbc14.jar 10.2.0.4.0, Java 5, Java 6
Description
Hello,
This happend to me when using Ibatis 3 beta 3. Also happens with beta 2. I did not test beta 1.
Database: oracle 10g, using ojdbc14.jar 10.2.0.4.0. Happens on Java 5 and Java 6.
The exception:
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
Also happens if I use Long instead of Integer:
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
The Exception happens when accessing the results, not during the query execution.
The query , from ProductMapper.xml
<select id="selectProductCodes" resultType="Integer">
select distinct productcode from product
</select>
productcode defined on product table as NUMBER(5) not null,
The test code:
------------------------
import java.util.List;
public class Test {
public static void main(String[] args)
{ List<Integer> codes = ProductDA.selectProductCodes(); for (Integer code: codes) System.out.println("code: " + code); }}
------------------------
ProductDA.java:
------------------------
import java.util.List;
import org.apache.ibatis.session.SqlSession;
public class ProductDA {
public static List<Integer> selectProductCodes() {
SqlSession session = Ibatis.getSession();
try
{ ProductMapper productMapper = session.getMapper(ProductMapper.class); return productMapper.selectProductCodes(); }finally
{ session.close(); }}
}
------------------------
ProductMapper.java:
------------------------
public interface ProductMapper
{ List<Integer> selectProductCodes() ; }------------------------
Ibatis.java:
------------------------
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class Ibatis {
private static SqlSessionFactory sqlSessionFactory;
private Ibatis () {
}
private static synchronized void init () {
if (sqlSessionFactory == null)
try
catch (Exception e)
{ throw new RuntimeException(e); }}
public static SqlSession getSession()
{ if (sqlSessionFactory == null) init(); return sqlSessionFactory.openSession(); } }
------------------------
Ibatis.xml (partial):
<environment id="test">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:ORACLE10G"/>
<property name="username" value="username"/>
<property name="password" value="***"/>
</dataSource>
</environment>