java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

在开发中,遇到这么一个错误:


报错的意思: Long 无法转化成Integer类型.

网上的解释是:

    这里在Hibernate2.0之前版本list.get(0)返回的是Integer类型.但是在Hibernate3.0以后版本list.get(0)返回的是Long类型.所以在这里不可以由Long型强转成Integer类型.

    这里我用的是mybais3.X版本,同样是一个原因,我在resultMap返回参数的时候,没有定义一个productType这个字段,默认返回为Long型,导致我在java中代码取这个字段值,用Integer变量时报上述错误。


    先前是没有定义上述关于product_type这个字段,下面这里就会报上述的错误。

Integer productType = (Integer) product.get("product_type");
      这篇博文的目的:大家在遇到类似的错误时,知道从哪里入手

猜你喜欢

转载自blog.csdn.net/zouxucong/article/details/79643267