org.hibernate.PropertyAccessException: IllegalArgumentException

org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.hengbao.otp.bean.AuthStatusBean.sum

 调用sql语句遇到这个问题,是因为hibernate版本或者所使用的数据库默认数据格式造成的,尤其是在进行sum,count等函数操作时,换了一圈的int,Integer,long,Long,最后没办法,虽知不可能还是试了doubel,晕死。还不行。

最后没办法,只好变通,不采用hibernate的

createQuery

 或createSQLQuery

createSQLQuery

 转而采用

getNamedQuery

 的方式,在xml文件中,指定对应字段对应的类型,一运行,测试文件,OK,总算通过了。

由此想到本人以前做的一个:

select new com.gu.vo.StatisticsVO(sum(amount) as sumMoney,"+columnName+" as groupColumns) from TransRecordVO where status=1"

 也是一直报这个错误,有的人说是因为

StatisticsVO

的构造方法的类型与查询结果的类型不符造成的,也是试了一圈,没有成功,最后无法。只好修改数据库中对应字段的类型,转了一大圈才解决的。

现在看来,完全也可以采用上述方法指定,对应字段的类型来解决的!

xml文件代码:

<!-- 统计令牌状态 -->
	<sql-query name="countStatus">
		<return-scalar column="id" type="java.lang.Integer" />
		<return-scalar column="authId" type="java.lang.Integer" />
		<return-scalar column="sum" type="java.lang.Integer" />
		<return-scalar column="tokenStatus" type="java.lang.Integer" />
	<![CDATA[
		  SELECT t.id AS id,t.auth_id AS authId,COUNT(t.token_status) AS sum, t.token_status AS tokenStatus FROM 
          t_auth_oprate t WHERE t.auth_id =:authId  AND (T.operate_time BETWEEN :startDate AND :endDate) 
          GROUP BY t.token_status
	]]>

 至于id是Integer还是Long完全可以自由定义转化。当然必须要与返回的bean中对应字段的类型一致。

猜你喜欢

转载自gwh-08.iteye.com/blog/1596042