I just solved this problem, here is my code
Criteria criteria = session.createCriteria(ProductOffer.class); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Date effDate = TypeConvertUtil.toDate(param.get("effDate")); criteria.add(Restrictions.le("effDate", effDate)); criteria.add(Restrictions.gt("expDate", effDate)); criteria.createAlias("productOfferPropDefs", "def",JoinType.LEFT_OUTER_JOIN); criteria.setFetchMode("productOfferPropDefs", FetchMode.JOIN); criteria.add(Restrictions.le("def.effDate", effDate)); criteria.add(Restrictions.gt("def.expDate", effDate)); criteria.createAlias("def.productOfferProps", "prop",JoinType.LEFT_OUTER_JOIN); criteria.setFetchMode("def.productOfferProps", FetchMode.JOIN); criteria.add(Restrictions.le("prop.effDate", effDate)); criteria.add(Restrictions.gt("prop.expDate", effDate)); productOfferList = criteria.list();
note that
criteria.createAlias("productOfferPropDefs", "def",JoinType.LEFT_OUTER_JOIN);
This parameter is important:
JoinType.LEFT_OUTER_JOIN
if you have not used it, and your one-to-many relationship, it will fall into the 1: N classic problem for sleep mode
source share