tags:

views:

17

answers:

0

Hi,

I need to fetch List of Property(parent) Objects, if the Property has the Child object called propertyConcern i need to verify whether this propertyConcern is mapped to statement(verifying in detach query).

 // Fetches associated Properties
            DetachedCriteria subquery = DetachedCriteria.forClass(
                    PropertyConcernStatement.class, "prtCrnStmt");
            subquery.add(Restrictions.eq("prtCrnStmt.statementId", statement));
            subquery.setProjection(Projections
                    .groupProperty("prtCrnStmt.propertyConcern.prtyCrnId"));

// Criteria to retrive unassociated concerns
            Criteria criteria = getPersManager().getCurrentSession()
                    .createCriteria(Property.class, "property").createAlias(
                            "property.propertyType", "type").createAlias(
                            "property.propertyConcern", "propertyConcern",
                            CriteriaSpecification.LEFT_JOIN).createAlias(
                            "propertyConcern.concern", "concern",
                            CriteriaSpecification.INNER_JOIN).setResultTransformer(
                            CriteriaSpecification.DISTINCT_ROOT_ENTITY);

            criteria.add(Restrictions.or(Restrictions
                    .isEmpty("property.propertyConcern"), Subqueries.propertyNotIn(
                    "propertyConcern.prtyCrnId", subquery)));

        // Not
        // associated