Example usage for org.hibernate FetchMode SELECT

List of usage examples for org.hibernate FetchMode SELECT

Introduction

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

Prototype

FetchMode SELECT

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

Click Source Link

Document

Fetch eagerly, using a separate select.

Usage

From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java

License:Apache License

private void addFetchStrategy(Criteria criteria) {
    for (ConditionalCriteria crit : cndCriterias) {
        if (Operator.FetchEager.equals(crit.getOperator())) {
            criteria.setFetchMode(crit.getPropertyFullName(), FetchMode.JOIN);
        } else if (Operator.FetchLazy.equals(crit.getOperator())) {
            criteria.setFetchMode(crit.getPropertyFullName(), FetchMode.SELECT);
        }/*from   w w  w  . j a  va  2s  .  com*/
    }
}

From source file:org.grails.orm.hibernate.query.AbstractHibernateQuery.java

License:Apache License

@Override
public Query select(String property) {
    this.hasJoins = true;
    if (criteria != null)
        criteria.setFetchMode(property, FetchMode.SELECT);
    else if (detachedCriteria != null)
        detachedCriteria.setFetchMode(property, FetchMode.SELECT);
    return this;
}

From source file:org.mzd.shap.domain.authentication.UserDaoSpringHibernate.java

License:Open Source License

public List<UserView> getUsers() {
    return getHibernateTemplate().execute(new HibernateCallback<List<UserView>>() {
        @Override/*ww w .ja va  2s .  co  m*/
        @SuppressWarnings("unchecked")
        public List<UserView> doInHibernate(Session session) throws HibernateException, SQLException {
            List<User> users = session.createCriteria(getPersistentClass()).addOrder(Order.asc("name"))
                    .setFetchMode("roles", FetchMode.SELECT).list();

            List<UserView> view = new ArrayList<UserView>(users.size());
            for (User u : users) {
                view.add(new UserView(u));
            }

            return view;
        }
    });
}

From source file:org.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java

License:Apache License

private void addFetchStrategy(Criteria criteria) {
    List<Property<?>> eagerProps = new ArrayList<Property<?>>(
            Arrays.asList(fetchEager != null ? fetchEager : new Property<?>[] {}));
    for (ConditionalCriteria crit : cndCriterias) {
        if (Operator.FetchEager.equals(crit.getOperator())) {
            criteria.setFetchMode(crit.getPropertyFullName(), FetchMode.JOIN);
            removeProp(eagerProps, crit);
        } else if (Operator.FetchLazy.equals(crit.getOperator())) {
            criteria.setFetchMode(crit.getPropertyFullName(), FetchMode.SELECT);
            removeProp(eagerProps, crit);
        }/*from   ww w.j av  a  2  s. c  o  m*/
    }
    for (Property<?> p : eagerProps) {
        criteria.setFetchMode(p.getName(), FetchMode.JOIN);
    }
}

From source file:org.theospi.portfolio.wizard.mgt.impl.WizardManagerImpl.java

License:Educational Community License

protected List findPublishedWizardsLazy(List<String> sites) {
    Criteria c = this.getSession().createCriteria(Wizard.class);
    Criteria rootCat = c.createCriteria("rootCategory");
    rootCat.setFetchMode("childPages", FetchMode.SELECT);
    rootCat.setFetchMode("childCategories", FetchMode.SELECT);
    c.add(Expression.eq("published", Boolean.valueOf(true)));
    c.add(Expression.in("siteId", sites));

    return new ArrayList(c.list());
}

From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java

License:Open Source License

/**
 * Handle fetch selections.//from w w w  .  j a va  2s . c  o  m
 * @param qc
 */
private void handleFetch(QCriteriaQueryBase<?, ?> qc) {
    for (Map.Entry<String, QFetchStrategy> ms : qc.getFetchStrategies().entrySet()) {
        PropertyMetaModel<?> pmm = MetaManager.findPropertyMeta(m_rootClass, ms.getKey());
        if (null == pmm)
            throw new QQuerySyntaxException(
                    "The 'fetch' path '" + ms.getKey() + " does not resolve on class " + m_rootClass);
        if (ms.getValue() == QFetchStrategy.LAZY)
            continue;

        switch (pmm.getRelationType()) {
        case DOWN:
            m_rootCriteria.setFetchMode(ms.getKey(), FetchMode.SELECT);
            break;
        //               throw new QQuerySyntaxException("The 'fetch' path '" + ms.getKey()
        //                  + " is a child relation (list-of-children). Fetch is not yet supported for that because Hibernate will duplicate the master.");

        case UP:
            m_rootCriteria.setFetchMode(ms.getKey(), FetchMode.JOIN);
            break;

        case NONE:
            throw new QQuerySyntaxException(
                    "The 'fetch' path '" + ms.getKey() + " is not recognized as a relation property");
        }
    }
}