Example usage for org.hibernate Criteria setFetchMode

List of usage examples for org.hibernate Criteria setFetchMode

Introduction

In this page you can find the example usage for org.hibernate Criteria setFetchMode.

Prototype

public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;

Source Link

Document

Specify an association fetching strategy for an association or a collection of values.

Usage

From source file:org.hoteia.qalingo.core.dao.impl.MarketDaoImpl.java

License:Apache License

private void addDefaultMarketFetch(Criteria criteria) {
    criteria.setFetchMode("marketPlace", FetchMode.JOIN);
    criteria.setFetchMode("marketAreas", FetchMode.JOIN);
    criteria.setFetchMode("marketAttributes", FetchMode.JOIN);

    criteria.createAlias("marketAreas.defaultLocalization", "defaultLocalization", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("defaultLocalization", FetchMode.JOIN);

    criteria.createAlias("marketAreas.localizations", "localizations", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("localizations", FetchMode.JOIN);

    criteria.createAlias("marketAreas.retailers", "retailers", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("retailers", FetchMode.JOIN);

    criteria.createAlias("marketAreas.marketAreaAttributes", "marketAreaAttributes", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("marketAreaAttributes", FetchMode.JOIN);
}

From source file:org.hoteia.qalingo.core.dao.impl.MarketDaoImpl.java

License:Apache License

private void addDefaultMarketAreaFetch(Criteria criteria) {

    criteria.setFetchMode("catalog", FetchMode.JOIN);

    criteria.createAlias("catalog.catalogMaster", "catalogMaster", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("catalogMaster", FetchMode.JOIN);

    criteria.setFetchMode("market", FetchMode.JOIN);

    criteria.setFetchMode("defaultCurrency", FetchMode.JOIN);
    criteria.setFetchMode("currencies", FetchMode.JOIN);

    criteria.setFetchMode("marketAreaAttributes", FetchMode.JOIN);

    criteria.setFetchMode("defaultLocalization", FetchMode.JOIN);
    criteria.setFetchMode("localizations", FetchMode.JOIN);

    criteria.setFetchMode("defaultRetailer", FetchMode.JOIN);
    criteria.setFetchMode("retailers", FetchMode.JOIN);

    criteria.setFetchMode("deliveryMethods", FetchMode.JOIN);

    criteria.createAlias("deliveryMethods.countries", "deliveryMethodCountries", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("deliveryMethodCountries", FetchMode.JOIN);

    criteria.createAlias("deliveryMethods.prices", "deliveryMethodPrices", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("deliveryMethodPrices", FetchMode.JOIN);

    criteria.setFetchMode("paymentGateways", FetchMode.JOIN);
}

From source file:org.hoteia.qalingo.core.dao.impl.OrderCustomerDaoImpl.java

License:Apache License

private void addDefaultFetch(Criteria criteria) {
    criteria.setFetchMode("billingAddress", FetchMode.JOIN);
    criteria.setFetchMode("shippingAddress", FetchMode.JOIN);

    criteria.setFetchMode("orderPayments", FetchMode.JOIN);
    criteria.setFetchMode("orderShipments", FetchMode.JOIN);

    criteria.createAlias("orderShipments.orderItems", "orderItems", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("orderItems", FetchMode.JOIN);

    criteria.createAlias("orderShipments.orderItems.productSku", "productSku", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("productSku", FetchMode.JOIN);

    criteria.createAlias("orderShipments.orderItems.productSku.productSkuAttributes", "productSkuAttributes",
            JoinType.LEFT_OUTER_JOIN);//from w  w  w  . java2  s.  com
    criteria.setFetchMode("productSkuAttributes", FetchMode.JOIN);

    criteria.createAlias("orderShipments.orderItems.productSku.assets", "assets", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("assets", FetchMode.JOIN);

    criteria.createAlias("orderShipments.orderItems.orderTaxes", "orderTaxes", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("orderTaxes", FetchMode.JOIN);

    criteria.createAlias("orderShipments.orderItems.currency", "currency", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("currency", FetchMode.JOIN);

}

From source file:org.hoteia.qalingo.core.dao.impl.PaymentGatewayDaoImpl.java

License:Apache License

private void addDefaultFetch(Criteria criteria) {
    criteria.setFetchMode("paymentGatewayAttributes", FetchMode.JOIN);
}

From source file:org.hoteia.qalingo.core.dao.impl.ProductDaoImpl.java

License:Apache License

public List<ProductMarketing> findProductMarketingsByBrandId(final Long brandId) {
    Criteria criteria = createDefaultCriteria(ProductMarketing.class);

    addDefaultProductMarketingFetch(criteria);

    criteria.setFetchMode("productBrand", FetchMode.JOIN);
    criteria.createAlias("productBrand", "pb", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("pb.id", brandId));

    criteria.addOrder(Order.asc("id"));

    @SuppressWarnings("unchecked")
    List<ProductMarketing> productMarketings = criteria.list();
    return productMarketings;
}

From source file:org.hoteia.qalingo.core.dao.impl.ProductDaoImpl.java

License:Apache License

public List<ProductMarketing> findProductMarketingsByBrandCode(final String brandCode) {
    Criteria criteria = createDefaultCriteria(ProductMarketing.class);

    addDefaultProductMarketingFetch(criteria);

    criteria.setFetchMode("productBrand", FetchMode.JOIN);
    criteria.createAlias("productBrand", "pb", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("pb.code", brandCode));

    criteria.addOrder(Order.asc("id"));

    @SuppressWarnings("unchecked")
    List<ProductMarketing> productMarketings = criteria.list();
    return productMarketings;
}

From source file:org.hoteia.qalingo.core.dao.impl.ProductDaoImpl.java

License:Apache License

public List<ProductMarketing> findProductMarketingsByCatalogCategoryCode(final String categoryCode) {
    Criteria criteria = createDefaultCriteria(ProductMarketing.class);

    addDefaultProductMarketingFetch(criteria);

    criteria.setFetchMode("defaultCatalogCategory", FetchMode.JOIN);
    criteria.createAlias("defaultCatalogCategory", "dc", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("dc.code", categoryCode));

    criteria.addOrder(Order.asc("id"));

    @SuppressWarnings("unchecked")
    List<ProductMarketing> productMarketings = criteria.list();
    return productMarketings;
}

From source file:org.hoteia.qalingo.core.dao.impl.ProductDaoImpl.java

License:Apache License

public List<ProductMarketing> findProductMarketingsByCatalogCategoryCodeAndSortAndPagintion(
        final String categoryCode, int pageNumber, int pageSize, String sortBy, String orderBy) {
    Criteria criteria = getSession().createCriteria(ProductMarketing.class);

    addDefaultProductMarketingFetch(criteria);

    criteria.setFetchMode("defaultCatalogCategory", FetchMode.JOIN);
    criteria.createAlias("defaultCatalogCategory", "dc", JoinType.LEFT_OUTER_JOIN);

    criteria.add(Restrictions.eq("dc.code", categoryCode));
    if ("desc".equals(orderBy)) {
        criteria.addOrder(Order.desc(sortBy));
    } else {/*from w w w  .  j a v  a 2s. c  o m*/
        criteria.addOrder(Order.asc(sortBy));
    }

    criteria.setFirstResult((pageNumber - 1) * pageSize);
    criteria.setMaxResults(pageSize);

    @SuppressWarnings("unchecked")
    List<ProductMarketing> productMarketings = criteria.list();
    return productMarketings;
}

From source file:org.hoteia.qalingo.core.dao.impl.ProductDaoImpl.java

License:Apache License

private void addDefaultProductMarketingFetch(Criteria criteria) {
    criteria.setFetchMode("productBrand", FetchMode.JOIN);
    criteria.setFetchMode("productMarketingType", FetchMode.JOIN);
    criteria.setFetchMode("productMarketingAttributes", FetchMode.JOIN);

    criteria.setFetchMode("productSkus", FetchMode.JOIN);
    criteria.createAlias("productSkus.prices", "prices", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("prices", FetchMode.JOIN);

    criteria.createAlias("productSkus.prices.currency", "currency", JoinType.LEFT_OUTER_JOIN);
    criteria.setFetchMode("currency", FetchMode.JOIN);

    criteria.setFetchMode("productAssociationLinks", FetchMode.JOIN);
    criteria.setFetchMode("assets", FetchMode.JOIN);
    criteria.setFetchMode("defaultCatalogCategory", FetchMode.JOIN);
}