Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductAttributeDao.java

License:Open Source License

public ProductAttribute findById(long id) {
    try {/*ww w . j av  a 2 s. c  o m*/
        /**
         * ProductAttribute instance =
         * (ProductAttribute)super.getHibernateTemplate()
         * .get("com.salesmanager.core.entity.catalog.ProductAttribute",
         * id);
         **/

        /**
         * if(instance!=null) {
         * Hibernate.initialize(instance.getProductOption());
         * Hibernate.initialize(instance.getProductOptionValue()); }
         **/

        ProductAttribute instance = (ProductAttribute) super.getSession().createCriteria(ProductAttribute.class)
                .add(Restrictions.eq("productAttributeId", id)).setFetchMode("productOption", FetchMode.JOIN)
                .setFetchMode("productOptionValue", FetchMode.JOIN).uniqueResult();

        return instance;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductAttributeDao.java

License:Open Source License

public ProductAttribute findByProductIdAndOptionValueId(long productId, long productOptionValueId) {
    try {//from   w w  w. j a  v a 2s. co  m
        ProductAttribute attr = (ProductAttribute) super.getSession().createCriteria(ProductAttribute.class)
                .add(Restrictions.eq("productId", productId))
                .add(Restrictions.eq("optionValueId", productOptionValueId))
                .setFetchMode("productOption", FetchMode.JOIN)
                .setFetchMode("productOptionValue", FetchMode.JOIN).uniqueResult();

        return attr;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.salesmanager.core.service.catalog.impl.db.dao.ProductOptionDao.java

License:Open Source License

public ProductOption findOptionsValuesByProductOptionId(long productOptionId) {
    try {/*from w w  w  .  j a v  a  2  s .c om*/

        ProductOption option = (ProductOption) super.getSession().createCriteria(ProductOption.class)
                .add(Restrictions.eq("productOptionId", productOptionId))
                .addOrder(Order.asc("productOptionSortOrder")).setFetchMode("descriptions", FetchMode.JOIN)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).uniqueResult();

        if (option != null) {
            Hibernate.initialize(option.getValues());
        }
        return option;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    }
}

From source file:com.scopix.periscope.corporatestructuremanagement.dao.CorporateStructureManagementHibernateDAOImpl.java

License:Open Source License

/**
 * Obtain a list of EvidenceExtractionServicesServer object using filters.
 *
 * @param eess Filter object//w w  w. j ava  2 s.c om
 * @return List<EvidenceExtractionServicesServer> List of EvidenceExtractionServicesServer objects
 */
@Override
public List<EvidenceExtractionServicesServer> getEvidenceExtractionServicesServersList(
        EvidenceExtractionServicesServer eess) {
    List<EvidenceExtractionServicesServer> list = null;
    Criteria criteria = this.getSession().createCriteria(EvidenceExtractionServicesServer.class);
    criteria.addOrder(Order.asc("id"));
    if (eess != null) {
        if (eess.getEvidenceServicesServer() != null && eess.getEvidenceServicesServer().getId() != null
                && eess.getEvidenceServicesServer().getId() > 0) {
            criteria.add(
                    Restrictions.eq("evidenceServicesServer.id", eess.getEvidenceServicesServer().getId()));
        }
        if (eess.getUrl() != null && eess.getUrl().length() > 0) {
            criteria.add(Restrictions.ilike("url", eess.getUrl(), MatchMode.ANYWHERE));
        }
        if (eess.getStores() != null && eess.getStores().size() > 0) {
            List<String> names = new LinkedList<String>();
            for (Store store : eess.getStores()) {
                names.add(store.getName());
            }
            criteria.setFetchMode("Place", FetchMode.JOIN).add(Restrictions.in("name", names));
        }
    }
    list = criteria.list();
    return list;
}

From source file:com.selfsoft.baseinformation.service.impl.TbCustomerServiceImpl.java

public List<TbCustomer> findByTbCustomer(TbCustomer tbCustomer, String types) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCustomer.class);

    if (null != tbCustomer) {
        if (null != tbCustomer.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbCustomer.getId()));
        }/*w  w  w  . jav a2 s  . c o  m*/
        if (null != tbCustomer.getCustomerCode() && !"".equals(tbCustomer.getCustomerCode())) {
            detachedCriteria.add(Restrictions.like("customerCode", "%" + tbCustomer.getCustomerCode() + "%"));
        }
        if (null != tbCustomer.getCustomerName() && !"".equals(tbCustomer.getCustomerName())) {
            detachedCriteria.add(Restrictions.like("customerName", "%" + tbCustomer.getCustomerName() + "%"));
        }
        if (null != tbCustomer.getPinyinCode() && !"".equals(tbCustomer.getPinyinCode())) {
            detachedCriteria.add(Restrictions.like("pinyinCode", "%" + tbCustomer.getPinyinCode() + "%"));
        }
        if (null != tbCustomer.getTelephone() && !"".equals(tbCustomer.getTelephone())) {
            detachedCriteria.add(Restrictions.like("telephone", "%" + tbCustomer.getTelephone() + "%"));
        }
        if (null != tbCustomer.getCustomerProperty()) {
            detachedCriteria.add(Restrictions.eq("customerProperty", tbCustomer.getCustomerProperty()));
        }
        if (null != tbCustomer.getTmCustomerType()) {
            detachedCriteria.setFetchMode("tmCustomerType", FetchMode.JOIN);
            if (null != tbCustomer.getTmCustomerType().getId()) {
                detachedCriteria
                        .add(Restrictions.eq("tmCustomerType.id", tbCustomer.getTmCustomerType().getId()));
            }
        }

    }
    if (StringUtils.isNotBlank(types)) {
        List<Long> list = new ArrayList<Long>();
        for (String type : types.split(",")) {
            list.add(new Long(type));
        }

        detachedCriteria.add(Restrictions.in("customerProperty", list));
    }
    return tbCustomerDao.findByCriteria(detachedCriteria, tbCustomer);
}

From source file:com.selfsoft.baseinformation.service.impl.TbCustomerServiceImpl.java

public List<TbCustomer> findByTbCustomer(TbCustomer tbCustomer) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCustomer.class);

    if (null != tbCustomer) {
        if (null != tbCustomer.getId()) {
            detachedCriteria.add(Restrictions.eq("id", tbCustomer.getId()));
        }/*  w  ww .  j  a  va2  s .c om*/
        if (null != tbCustomer.getCustomerCode() && !"".equals(tbCustomer.getCustomerCode())) {
            detachedCriteria.add(Restrictions.like("customerCode", "%" + tbCustomer.getCustomerCode() + "%"));
        }
        if (null != tbCustomer.getCustomerName() && !"".equals(tbCustomer.getCustomerName())) {
            detachedCriteria.add(Restrictions.like("customerName", "%" + tbCustomer.getCustomerName() + "%"));
        }
        if (null != tbCustomer.getPinyinCode() && !"".equals(tbCustomer.getPinyinCode())) {
            detachedCriteria.add(Restrictions.like("pinyinCode", "%" + tbCustomer.getPinyinCode() + "%"));
        }
        if (null != tbCustomer.getTelephone() && !"".equals(tbCustomer.getTelephone())) {
            detachedCriteria.add(Restrictions.like("telephone", "%" + tbCustomer.getTelephone() + "%"));
        }
        if (null != tbCustomer.getCustomerProperty()) {
            detachedCriteria.add(Restrictions.eq("customerProperty", tbCustomer.getCustomerProperty()));
        }
        if (null != tbCustomer.getTmCustomerType()) {
            detachedCriteria.setFetchMode("tmCustomerType", FetchMode.JOIN);
            if (null != tbCustomer.getTmCustomerType().getId()) {
                detachedCriteria
                        .add(Restrictions.eq("tmCustomerType.id", tbCustomer.getTmCustomerType().getId()));
            }
        }
    }

    return tbCustomerDao.findByCriteria(detachedCriteria, tbCustomer);
}

From source file:com.smartitengineering.dao.impl.hibernate.AbstractDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
private void processNestedParameter(Criteria criteria, String element, QueryParameter parameter) {
    FetchMode mode;//w  w w. ja  v  a2  s. com
    CompositionQueryParameter queryParameter = QueryParameterCastHelper.COMPOSITION_PARAM_FOR_NESTED_TYPE
            .cast(parameter);
    switch (queryParameter.getFetchMode()) {
    case EAGER:
        mode = FetchMode.EAGER;
        break;
    case SELECT:
        mode = FetchMode.SELECT;
        break;
    case JOIN:
        mode = FetchMode.JOIN;
        break;
    case LAZY:
        mode = FetchMode.LAZY;
        break;
    default:
    case DEFAULT:
        mode = FetchMode.DEFAULT;
        break;
    }
    criteria.setFetchMode(element, ((mode == null) ? FetchMode.JOIN : mode));
    Collection<QueryParameter> nestedParameters = queryParameter.getNestedParameters();
    if (nestedParameters == null || nestedParameters.size() <= 0) {
        return;
    }
    Criteria nestedCriteria = criteria.createCriteria(element);
    for (QueryParameter nestedQueryParameter : nestedParameters) {
        if (!nestedQueryParameter.isInitialized()) {
            continue;
        }
        processCriteria(nestedCriteria, getPropertyName(nestedQueryParameter), nestedQueryParameter);
    }
}

From source file:com.sonymobile.backlogtool.Util.java

License:Open Source License

/**
 * Returns the area with argument name if it exists.
 * @param areaName Area name to search for
 * @param sessionFactory hibernate session factory
 * @return area//from  w  ww . j  a v a  2 s  .  c  om
 */
public static Area getArea(String areaName, SessionFactory sessionFactory) {
    Area area = null;

    Session session = sessionFactory.openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();

        area = (Area) session.createCriteria(Area.class).add(Restrictions.like("name", areaName))
                .setFetchMode("storyAttr1", FetchMode.JOIN).setFetchMode("storyAttr2", FetchMode.JOIN)
                .setFetchMode("storyAttr3", FetchMode.JOIN).setFetchMode("taskAttr1", FetchMode.JOIN)
                .setFetchMode("editors", FetchMode.JOIN).setFetchMode("admins", FetchMode.JOIN).uniqueResult();

        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return area;
}

From source file:com.valco.dao.NotasVentaDAO.java

public List<NotasDeVenta> getNotasDeVenta() throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;// w w  w . j  a va2 s .  com
    List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(NotasDeVenta.class).setFetchMode("repartidores", FetchMode.JOIN);
        q.setFetchMode("productosInventarios", FetchMode.SELECT).setFetchMode("clientes", FetchMode.JOIN)
                .add(Restrictions.eq("estatus", "ASIGNADA"));
        notas = (List<NotasDeVenta>) q.list();
        return notas;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los clientes.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los clientes.");
        }
    }
}

From source file:com.valco.dao.NotasVentaDAO.java

public List<NotasDeVenta> getAsignacionNotasDeVenta() throws Exception {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from www .  jav a  2s.  c o  m*/
    List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>();
    try {
        tx = session.beginTransaction();
        Criteria q = session.createCriteria(NotasDeVenta.class).setFetchMode("repartidores", FetchMode.JOIN);
        q.setFetchMode("productosInventarios", FetchMode.SELECT);

        notas = (List<NotasDeVenta>) q.list();
        return notas;

    } catch (HibernateException he) {
        throw new Exception("Ocurri un error al consultar los clientes.");

    } finally {
        try {
            if (session.isOpen()) {
                session.close();
            }
        } catch (HibernateException he) {
            throw new Exception("Ocurri un error al consultar los clientes.");
        }
    }
}