日期:2014-05-20  浏览次数:20941 次

hibernate Criteria查询问题。
createCriteria.forClass(A.class).add(Restrictions.like("customerId",arg[0].toString()+"%")) 这个怎么老是提示说java.lang.String cannot be cast to java.lang.Integerjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer 转换String我试过了 转换成Int我也试过了 不明白它到底要穿什么类型的参数。请问过的指点一下 谢谢。数组肯定是对的没有问题。现在就是不清楚到底要穿什么类型的值。转换String int 我都试了。


------解决方案--------------------
肯定不是这句话出的错误,可以把上下文的贴出来看看么?
------解决方案--------------------
like("customerId",arg[0].toString()+"%")
customerId 是 类 A里面的属性,属性是什么类型就传什么类型。

------解决方案--------------------
like(String column, Object obj)方法是不用加%的,你的"customerId"应该是定义的Integer类型,所以你后面的对应参数也要是Integer,而你传的是带“%”字符串(无法转为Integer)
------解决方案--------------------
探讨

like(String column, Object obj)方法是不用加%的,你的"customerId"应该是定义的Integer类型,所以你后面的对应参数也要是Integer,而你传的是带“%”字符串(无法转为Integer)