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:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleDAO.java

License:Apache License

private List<SamplePE> listSamplesByCriteria(final Criteria basicCriteria, boolean withExperimentAndProperties,
        Criterion... additionalCriterions) throws DataAccessException {
    for (Criterion criterion : additionalCriterions) {
        basicCriteria.add(criterion);//from   w  w  w. j av a2s. c o  m
    }
    final int count = DAOUtils.getCount(basicCriteria);
    if (withExperimentAndProperties) {
        basicCriteria.setFetchMode("experimentInternal", FetchMode.JOIN);
        if (count <= DAOUtils.MAX_COUNT_FOR_PROPERTIES) {
            basicCriteria.setFetchMode("sampleProperties", FetchMode.JOIN);
        } else {
            operationLog.info(String.format("Found %d samples, disable properties loading.", count));
        }
    }
    basicCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return cast(basicCriteria.list());
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleDAO.java

License:Apache License

public SamplePE tryToFindByPermID(String permID) throws DataAccessException {
    assert permID != null : "Unspecified permanent ID.";
    final Criteria criteria = getSession().createCriteria(ENTITY_CLASS);
    criteria.add(Restrictions.eq("permId", permID));
    criteria.setFetchMode("sampleType.sampleTypePropertyTypesInternal", FetchMode.JOIN);
    final SamplePE sample = (SamplePE) criteria.uniqueResult();
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("Following sample '%s' has been found for " + "permanent ID '%s'.",
                sample, permID));//from ww  w .j  a  v a 2  s .  c  o  m
    }
    return sample;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleDAO.java

License:Apache License

public final SamplePE tryFindByCodeAndDatabaseInstance(final String sampleCode,
        final DatabaseInstancePE databaseInstance) {
    assert sampleCode != null : "Unspecified sample code.";
    assert databaseInstance != null : "Unspecified database instance.";

    final Criteria criteria = getSession().createCriteria(ENTITY_CLASS);
    addSampleCodeCriterion(criteria, sampleCode);
    criteria.add(Restrictions.eq("databaseInstance", databaseInstance));
    criteria.setFetchMode("sampleType.sampleTypePropertyTypesInternal", FetchMode.JOIN);
    final SamplePE sample = (SamplePE) criteria.uniqueResult();
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format(
                "Following sample '%s' has been found for " + "code '%s' and database instance '%s'.", sample,
                sampleCode, databaseInstance));
    }//from  w  ww .  j a v  a2  s.co  m
    return sample;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleDAO.java

License:Apache License

public final SamplePE tryFindByCodeAndGroup(final String sampleCode, final GroupPE group) {
    assert sampleCode != null : "Unspecified sample code.";
    assert group != null : "Unspecified group.";

    final Criteria criteria = getSession().createCriteria(ENTITY_CLASS);
    addSampleCodeCriterion(criteria, sampleCode);
    criteria.add(Restrictions.eq("group", group));
    criteria.setFetchMode("sampleType.sampleTypePropertyTypesInternal", FetchMode.JOIN);
    final SamplePE sample = (SamplePE) criteria.uniqueResult();
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("Following sample '%s' has been found for code '%s' and group '%s'.",
                sample, sampleCode, group));
    }/*from ww  w.  j a v  a2 s  . c  o m*/
    return sample;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleTypeDAO.java

License:Apache License

public final List<SampleTypePE> listSampleTypes() throws DataAccessException {
    final DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
    criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance()));
    criteria.setFetchMode("sampleTypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
    final List<SampleTypePE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s: %d sample type(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), list.size()));
    }/*from w  w w  . j  a va 2  s.  c  om*/
    return list;
}

From source file:co.com.codesoftware.logic.facturas.FacturaLogic.java

/**
 * funcion que consulta el historial de un factura por su id
 *
 * @param idFactura// ww  w  . j ava  2 s. c o  m
 * @return
 */
public List<HistorialFacturaEntity> consultaHistorialFactura(Integer idFactura) {
    List<HistorialFacturaEntity> rta = null;
    try {
        initOperation();
        rta = sesion.createCriteria(HistorialFacturaEntity.class).setFetchMode("idUsuario", FetchMode.JOIN)
                .add(Restrictions.eq("idFactura", idFactura)).list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rta;
}

From source file:co.com.codesoftware.logic.ProductoLogic.java

/**
 * Funcion la cual busca un producto por medio de su codigo externo
 *
 * @param codExterno/*from w w  w.j  a v  a 2s  .c o  m*/
 * @return
 */
public List<ProductoEntity> consultaProductosXCodigoExt(String codExterno) {
    List<ProductoEntity> respuesta = null;
    try {
        this.initOperation();
        Criteria crit = sesion.createCriteria(ProductoEntity.class)
                .add(Restrictions.like("codigoExt", codExterno, MatchMode.ANYWHERE).ignoreCase())
                .setFetchMode("referencia", FetchMode.JOIN).setFetchMode("marca", FetchMode.JOIN)
                .setFetchMode("categoria", FetchMode.JOIN).setFetchMode("subcuenta", FetchMode.JOIN);
        respuesta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return respuesta;
}

From source file:co.com.codesoftware.logic.ProductoLogic.java

/**
 * metodo que consulta los productos sin dependencias, es decir sin
 * joincolumn//from  ww w. j  ava 2s. c  o m
 *
 * @return
 */
public List<ProductoSimpleEntity> consultaProductos() {
    List<ProductoSimpleEntity> respuesta = null;
    try {
        initOperation();
        Criteria crit = sesion.createCriteria(ProductoSimpleEntity.class);
        crit.setFetchMode("referenciaObj", FetchMode.JOIN);
        crit.setFetchMode("categoriaObj", FetchMode.JOIN);
        crit.setFetchMode("marcaObj", FetchMode.JOIN);
        crit.addOrder(Order.asc("id"));
        respuesta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return respuesta;
}

From source file:co.com.codesoftware.logic.ProductoLogic.java

/**
 * Funcion con la cual se realiza la consulta
 *
 * @param estado/*from   www .  jav  a2s . c o m*/
 * @return
 */
public List<PorcentajePrecioEntity> buscaPorcentajePrecio(String estado) {
    List<PorcentajePrecioEntity> rta = null;
    try {
        initOperation();
        Criteria crit = this.sesion.createCriteria(PorcentajePrecioEntity.class);
        crit.add(Restrictions.eq("estado", estado));
        crit.setFetchMode("sede", FetchMode.JOIN);
        crit.setFetchMode("categoria", FetchMode.JOIN);
        crit.setFetchMode("referencia", FetchMode.JOIN);
        crit.setFetchMode("marca", FetchMode.JOIN);
        //Query query = sesion.createQuery("from PorcentajePrecioEntity where estado = :estado ");
        //query.setString("estado", estado);

        rta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
        rta = null;
    }
    return rta;
}

From source file:co.com.codesoftware.logic.ProductoLogic.java

/**
 * Funcion con la cual se realiza la consulta de parametros basandose en una
 * sede y una categoria como minimo/*from   w  ww  .j  a v  a  2  s .co  m*/
 *
 * @param estado
 * @param idSede
 * @param idCate
 * @param idRefe
 * @param idMarca
 * @return
 */
public List<PorcentajePrecioEntity> buscaPorcentajePrecioXFiltros(String estado, Integer idSede, Integer idCate,
        Integer idRefe, Integer idMarca) {
    List<PorcentajePrecioEntity> rta;
    try {
        initOperation();
        Criteria criteria = sesion.createCriteria(PorcentajePrecioEntity.class);
        criteria.setFetchMode("sede", FetchMode.JOIN);
        criteria.setFetchMode("categoria", FetchMode.JOIN);
        criteria.setFetchMode("referencia", FetchMode.JOIN);
        criteria.setFetchMode("marca", FetchMode.JOIN);
        criteria.add(Restrictions.eq("estado", estado));
        criteria.add(Restrictions.eq("sede.id", idSede));
        criteria.add(Restrictions.eq("categoria.id", idCate));
        if (!"-1".equalsIgnoreCase(idRefe.toString().trim())) {
            criteria.add(Restrictions.eq("referencia.id", idRefe));
        }
        if (!"-1".equalsIgnoreCase(idMarca.toString().trim())) {
            criteria.add(Restrictions.eq("marca.id", idMarca));
        }

        rta = criteria.list();
    } catch (Exception e) {
        e.printStackTrace();
        rta = null;
    }
    return rta;
}