HQL查询无效

时间:2015-06-02 20:04:32

标签: java mysql hibernate hql

我在HQL中进行该查询并且没有检索到任何结果,但是当我执行它时 MySQL它的工作原理。你能帮我解决这个问题吗?

我复制了执行时在控制台中打印的sql查询 在我的代码中,并在MySQL中工作,完全相同的Query。谢谢你的帮助

    DetachedCriteria subquery = DetachedCriteria.forClass(ItineraryDay.class, "itineraryDay");
    subquery.add(Restrictions.eqProperty("itineraryDay.master", "this.master")).setProjection(Projections.rowCount());
    DetachedCriteria tourResults = DetachedCriteria.forClass(Tour.class, "tour");
    tourResults.createAlias("tour.master", "master");
    tourResults.createAlias("master.itinerariesDay", "itinerariesDay");
    tourResults.createAlias("itinerariesDay.itineraryDayDestinations", "itineraryDayDestinations");
    tourResults.createAlias("itineraryDayDestinations.destination", "destination");
    tourResults.createAlias("destination.country", "country");
    tourResults.setProjection(Projections.projectionList().add(Projections.groupProperty("tour.id")));
    if (dateIn != null) {
        tourResults.add(Restrictions.ge("dateIn", dateIn));
    }
    if (dateTo != null) {
        tourResults.add(Restrictions.ge("dateTo", dateIn));
    }
    if (!StringUtils.isBlank(name)) {
        tourResults.add(Restrictions.ilike("master.name", name, MatchMode.ANYWHERE));
    }
    if (quantity != null) {
        tourResults.add(Restrictions.le("master.minPassengers", quantity));
        tourResults.add(Restrictions.ge("master.maxPassengers", quantity));
    }

    if (country != null) {
        tourResults.add(Restrictions.eq("country.id", country));
    }

    if (sicDuration != null) {
        tourResults.add(Subqueries.in(sicDuration, subquery));
    }

    // tourResults.setProjection(Projections.projectionList().add(Projections.groupProperty("id")));

    // criteria.setResultTransformer(Transformers.aliasToBean(Tour.class));

    Criteria criteria = createCriteria().add(Subqueries.propertyIn("id", tourResults));

    return criteria.list();

0 个答案:

没有答案