hibernateからサブクエリを起動しようとしていますが、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")));