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:es.juntadeandalucia.panelGestion.persistencia.dao.impl.SchemaDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   www.  j a va2  s. com*/
public List<Schema> findByDataBase(long dataBaseId) {
    Criteria criteria = getSession().createCriteria(Schema.class);

    criteria.setFetchMode("dataBase", FetchMode.JOIN);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.eq("dataBase.id", dataBaseId));

    return criteria.list();
}

From source file:es.juntadeandalucia.panelGestion.persistencia.dao.impl.TableDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  w ww.j av a  2  s  . c  o  m
public List<Table> findBySchema(long schemaId) {
    Criteria criteria = getSession().createCriteria(Table.class);

    criteria.setFetchMode("schema", FetchMode.JOIN);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.eq("schema.id", schemaId));

    return criteria.list();
}

From source file:es.pode.auditoria.CriteriaSearch.java

/**
 * Locates a <code>Criteria</code> for a <code>childEntityName</code>. If a
 * <code>Criteria</code> exists for the <code>childEntityName</code>, it is returned. If
 * not, one is created and referenced in the <code>childCriteriaMap</code> under the
 * <code>childEntityName</code>.
 *
 * @param childEntityName/* w w  w.ja  v  a2s .  c  o m*/
 * @param parentCriteria
 * @return criteria The Criteria for the childEntityName.
 * @throws org.hibernate.HibernateException
 */
private org.hibernate.Criteria locateCriteria(String childEntityName, org.hibernate.Criteria parentCriteria)
        throws org.hibernate.HibernateException {
    if (this.childCriteriaMap.containsKey(childEntityName)) {
        return (org.hibernate.Criteria) this.childCriteriaMap.get(childEntityName);
    }
    org.hibernate.Criteria childCriteria = parentCriteria.createCriteria(childEntityName);
    if (this.configuration.isForceEagerLoading()) {
        parentCriteria.setFetchMode(childEntityName, org.hibernate.FetchMode.JOIN);
    }
    this.childCriteriaMap.put(childEntityName, childCriteria);
    return childCriteria;
}

From source file:es.sm2.openppm.core.dao.ActivitysellerDAO.java

License:Open Source License

/**
 * Get Activity sellers from Project/*from w w w  .j a  v a2s.c  o m*/
 *
  * @param joins
  * @param projects
 * @return
 */
public List<Activityseller> consActivitySellerByProject(List<String> joins, Project... projects) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    for (String join : joins) {
        crit.setFetchMode(join, FetchMode.JOIN);
    }

    crit.addOrder(Order.asc(Activityseller.IDACTIVITYSELLER)).createCriteria(Activityseller.PROJECTACTIVITY)
            .add(Restrictions.in(Projectactivity.PROJECT, projects));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ActivitysellerDAO.java

License:Open Source License

/**
 * Find seller associated project//  w  w w . ja va2s  .  c o m
 * @param projectactivity
 * @param joins
 * @return
 */
@SuppressWarnings("unchecked")
public List<Activityseller> findSellerAssociatedProject(Projectactivity projectactivity, List<String> joins) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    for (String join : joins) {
        crit.setFetchMode(join, FetchMode.JOIN);
    }

    crit.add(Restrictions.eq(Activityseller.PROJECTACTIVITY, projectactivity))
            .add(Restrictions.isNotNull(Activityseller.PROJECT));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.CalendarbaseDAO.java

License:Open Source License

/**
 * Return calendar base with exceptions/*w w  w . j  a va  2 s  . c om*/
 * @param calendarbase
 * @return
 */
public Calendarbase findByIdWithExceptions(Calendarbase calendarbase) {

    Criteria crit = getSession().createCriteria(getPersistentClass());
    crit.setFetchMode("calendarbaseexceptionses", FetchMode.JOIN);
    crit.add(Restrictions.eq("idCalendarBase", calendarbase.getIdCalendarBase()));

    return (Calendarbase) crit.uniqueResult();
}

From source file:es.sm2.openppm.core.dao.ChangeControlDAO.java

License:Open Source License

@Deprecated
public List<Changecontrol> findByProject(Project proj) {

    List<Changecontrol> list = null;

    if (proj != null) {

        Criteria crit = getSession().createCriteria(getPersistentClass())
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
                .add(Restrictions.eq(Changecontrol.PROJECT, proj));

        // Joins// w  ww .  ja  va 2s.c o  m
        crit.setFetchMode(Changecontrol.CHANGETYPE, FetchMode.JOIN);
        crit.setFetchMode(Changecontrol.CHANGEREQUESTWBSNODES, FetchMode.JOIN);

        // Order
        crit.addOrder(Order.asc(Changecontrol.CHANGEDATE));

        list = crit.list();
    }

    return list;
}

From source file:es.sm2.openppm.core.dao.ChangeControlDAO.java

License:Open Source License

/**
 * Find by Id and return data//  w w  w . j av a 2 s .c  o  m
 * @param change
 * @return
 */
public Changecontrol findByIdWithData(Changecontrol change) {

    Criteria crit = getSession().createCriteria(getPersistentClass());
    crit.setFetchMode("changetype", FetchMode.JOIN);
    crit.setFetchMode("wbsnode", FetchMode.JOIN);
    crit.add(Restrictions.eq("idChange", change.getIdChange()));

    return (Changecontrol) crit.uniqueResult();
}

From source file:es.sm2.openppm.core.dao.ChangeControlDAO.java

License:Open Source License

/**
 * Find change controls/*ww  w .  java2s. co  m*/
 *
 * @param search
 * @return
 */
public List<Changecontrol> find(ChangeControlSearch search) {

    List<Changecontrol> list = null;

    if (search.getIdProject() != null) {

        Criteria crit = getSession().createCriteria(getPersistentClass())
                .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
                .add(Restrictions.eq(Changecontrol.PROJECT, new Project(search.getIdProject())));

        // Joins
        crit.setFetchMode(Changecontrol.CHANGETYPE, FetchMode.JOIN);
        crit.setFetchMode(Changecontrol.CHANGEREQUESTWBSNODES, FetchMode.JOIN);

        // Filter by resolution
        if (search.getResolution() != null) {
            crit.add(Restrictions.eq(Changecontrol.RESOLUTION, search.getResolution()));
        }
        // Order
        crit.addOrder(Order.asc(Changecontrol.CHANGEDATE));

        list = crit.list();
    }

    return list;
}

From source file:es.sm2.openppm.core.dao.ContactDAO.java

License:Open Source License

/**
 * Return contact with company//from  w ww .j a  v a 2 s. co  m
 * @param contact
 * @return
 */
public Contact findByIdContact(Contact contact) {
    Contact cont = null;
    if (contact.getIdContact() != null) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        crit.setFetchMode("company", FetchMode.JOIN);
        crit.add(Restrictions.eq("idContact", contact.getIdContact()));
        cont = (Contact) crit.uniqueResult();
    }
    return cont;
}