org.hibernate.collection.PersistentSet cannot be cast to java.util.List
没写一对多关系之前可以运行,我也检查了对应关系没问题,只能麻烦各位帮忙了!publicList<Orders>getAdressbyUser(intid){Stringh...
没写一对多关系之前可以运行,我也检查了对应关系没问题,只能麻烦各位帮忙了!
public List<Orders> getAdressbyUser(int id){
String hql = "from Orders where userId = ?";
@SuppressWarnings("unchecked")
List<Orders> oList = s.createQuery(hql).setParameter(0, id).list();
return oList;
}
严重: Servlet.service() for servlet action threw exception
java.lang.ClassCastException: org.hibernate.collection.PersistentSet cannot be cast to java.util.List
at MyHibernate.code.Orders$$BulkBeanByCGLIB$$a7a2d084.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.DAO.GoodsDAO.getAdressbyUser(GoodsDAO.java:49)
at org.apache.jsp.Order_jsp._jspService(Order_jsp.java:99) 展开
public List<Orders> getAdressbyUser(int id){
String hql = "from Orders where userId = ?";
@SuppressWarnings("unchecked")
List<Orders> oList = s.createQuery(hql).setParameter(0, id).list();
return oList;
}
严重: Servlet.service() for servlet action threw exception
java.lang.ClassCastException: org.hibernate.collection.PersistentSet cannot be cast to java.util.List
at MyHibernate.code.Orders$$BulkBeanByCGLIB$$a7a2d084.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.DAO.GoodsDAO.getAdressbyUser(GoodsDAO.java:49)
at org.apache.jsp.Order_jsp._jspService(Order_jsp.java:99) 展开
2个回答
展开全部
PersistentSet cannot be cast to java.util.List 问题的关键就是这个了,类型转换错误
List<Orders> oList = s.createQuery(hql).setParameter(0, id).list(); 这里你确定返回的是ava.util.List 的集合?如果不是,自己修改一下,把s.createQuery(hql).setParameter(0, id).list()返回的类型改成ava.util.List即可
List<Orders> oList = s.createQuery(hql).setParameter(0, id).list(); 这里你确定返回的是ava.util.List 的集合?如果不是,自己修改一下,把s.createQuery(hql).setParameter(0, id).list()返回的类型改成ava.util.List即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询