"select c.type, c.date, sum(c.amount) from CustomerPayment c where c.date like '%" + year + "' and c.type='Cash'"
上面的hibernate查询给出了ClassCastError,因为我的select语句。休眠查询 - ClassCastError
我怎样才能以正确的方式写它?是否需要使用总结标准?以上查询有什么好处?我很困惑。
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to CustomerPayment
at tekirmobile.clController.getTotalCash(clController.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
我得到,因为您选择三个属性的上述查询
,但我选择所有他们得到正确的结果 – user2341009 2013-05-01 23:02:59
请尝试添加在您执行查询,并访问结果的代码,通过.LIST()或.uniqueResult():) – JustDanyul 2013-05-01 23:11:03
我用uniqueResult()但它仍然会导致问题 – user2341009 2013-05-01 23:12:40