7
我想火從休眠子查詢,但它顯示NPE :-(任何人都知道如何解決它的下面是代碼:休眠子查詢拋出空指針異常
DetachedCriteria criteria = DetachedCriteria.forClass(My.class,"A");
criteria.createAlias("A.a", "a");
criteria.createAlias("A.b", "b");
if(cValue !=null && cValue.size()>0){
criteria.add(Restrictions.in("b.c", cValue));
}
if(StringUtils.isNotEmpty(commodityList)){
DetachedCriteria commCriteria = DetachedCriteria.forClass(My.class,"A1");
commCriteria.createAlias("A1.a", "a1");
commCriteria.add(Restrictions.in("a1.name", commodityList.split(",")));
criteria.add(Subqueries.propertyIn("b.c", commCriteria));
}
criteria.addOrder(Order.asc("b.c"));
return getHibernateTemplate().findByCriteria(criteria);
堆棧跟蹤:
java.lang.NullPointerException
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:318)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:56)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1065)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1055)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1048)
at com.boeing.kmapi.base.skillset.dao.impl.EssSkillsetCommMapDAOImpl.getEssSkillsetCommMapforSkillsetIdList(EssSkillsetCommMapDAOImpl.java:51)
at com.boeing.kmapi.base.skillset.service.impl.EssGenericReportServiceImpl.filterCommodityDetails(EssGenericReportServiceImpl.java:87)
at com.boeing.kmapi.base.skillset.service.impl.EssGenericReportServiceImpl.getGenericReport(EssGenericReportServiceImpl.java:79)
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)
問題通過加入突起內部查詢原來決心。
commCriteria.createAlias("A1.b", "b1");
commCriteria.setProjection(Projections.projectionList().add(Projections.property("b1.c")));
發佈stacktrace並顯示至少拋出NPE的行。你試圖調試什麼? – 2013-03-26 06:26:38
如果解決了問題,請將解決問題的2行作爲此問題的答案發布,然後將其標記爲接受的答案 – 2013-03-26 08:51:23