问题描述
public List<Materials> findAllMaterialsByAppid(Integer appid) {String hql1 = "select medid from Materials where appid = ? and pid = 0";List<Materials> list = this.hibernateTemplate.find(hql1, appid);if (list != null && list.size() > 0) {if(list.get(0).getMedid() != null){Integer medid = (Integer)list.get(0).getMedid();String hql2 = "from Materials where appid = ? and pid = ?";return this.hibernateTemplate.find(hql2, appid, medid);}请教一下大家 问题补充:java.lang.ClassCastException: java.lang.Integer cannot be cast to com.gorgonor.modules.patients.entity.Materialsat com.gorgonor.modules.patients.dao.impl.MaterialsDaoImpl.findAllMaterialsByAppid(MaterialsDaoImpl.java:43)at com.gorgonor.modules.patients.service.impl.MaterialsServiceImpl.findAllMaterialsByAppid(MaterialsServiceImpl.java:22)at com.gorgonor.modules.patients.controller.DiskController.doctorDisk(DiskController.java:44)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)Materials属性private Integer medid;private Integer pid;private String title;private java.util.Date createtime;private Integer appid;private Integer filenum;private Integer filetotalsize;private String isprivate;private String creator;
解决方案
String hql1 = "from Materials where appid = ? and pid = 0";
解决方案二:
你SELECT 语句中是取 medid String hql1 = "select medid from Materials where appid = ? and pid = 0"; 但实际上你是相取是的Materials 这个对象这样的转换肯定有问题,你想要的SQL应该是这样的吧:String hql1 = "select * from Materials where appid = ? and pid = 0";
解决方案三:
最好贴完整一点,看看具体是哪一行报错。不过我猜测一下是不是这行的问题: Integer medid = (Integer)list.get(0).getMedid(); 你改为:Integer medid = (Integer)(list.get(0).getMedid()); 或者Integer medid = ((Materials)list.get(0)).getMedid(); 试试。
解决方案四:
Integer medid = (Integer)list.get(0).getMedid(); 应该是这行代码导致的。Materials中的属性medid是什么数据类型的?
解决方案五:
错误贴完整,Materials的各个属性贴上来