Example usage for org.hibernate.criterion Example excludeProperty

List of usage examples for org.hibernate.criterion Example excludeProperty

Introduction

In this page you can find the example usage for org.hibernate.criterion Example excludeProperty.

Prototype

public Example excludeProperty(String name) 

Source Link

Document

Exclude a particular property by name.

Usage

From source file:at.ac.tuwien.ifs.tita.dao.GenericHibernateDao.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String... excludeProps) {

    List<T> myList = null;//from w  w w.j a v a 2s .  c o m

    try {
        Criteria crit = getSession().createCriteria(this.persistenceClass);
        Example example = Example.create(exampleInstance);
        for (String exclude : excludeProps) {
            example.excludeProperty(exclude);
        }
        crit.add(example);
        // Tell Hibernate to remove duplicates from the result set if there
        // is a
        // OneToMany relation in the exampleInstance entity.
        crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

        myList = crit.list();
    } catch (Exception e) {
        throw new PersistenceException("Failure during reading entities (by example). Class="
                + this.persistenceClass.getSimpleName() + "\n" + e.getMessage(), e);
    }

    return myList;
}

From source file:bo.com.kibo.dal.impl.DAOGenericoHibernate.java

@Override
public List<T> buscarPorEjemplo(T exampleInstance, String... excludeProperty) {
    Criteria crit = getSession().createCriteria(getPersistentClass());
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
        example.excludeProperty(exclude);
    }/*from  w  w w. j a  v  a2s . c om*/
    crit.add(example);
    return crit.list();
}

From source file:br.gov.jfrj.siga.model.dao.ModeloDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public <T> List<T> consultar(final T exemplo, final String[] excluir) {
    final Criteria crit = getSessao().createCriteria(exemplo.getClass());
    final Example example = Example.create(exemplo);
    if (excluir != null) {
        for (final String exclude : excluir) {
            example.excludeProperty(exclude);
        }/*from w  w  w  . ja  va2s .com*/
    }
    crit.add(example);
    if (getCacheRegion() != null) {
        crit.setCacheable(true);
        crit.setCacheRegion(getCacheRegion());
    }
    return crit.list();
}

From source file:com.amkaawaken.DAO.hibernate.GenericHibernateDAO.java

@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
    Criteria crit = getSession().createCriteria(getPersistentClass());
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
        example.excludeProperty(exclude);
    }// w w w. j  a  v  a  2  s .  c  o m
    crit.add(example);
    return crit.list();
}

From source file:com.billing.ng.dao.impl.GenericDAOImpl.java

License:Open Source License

/**
 * Finds similar entities to the provided example, excluding an explicitly
 * ignored properties (as strings)./*from  w w  w  . jav a  2s  .  c o  m*/
 *
 * This method requires an underlying Hibernate persistence provider.
 *
 * @param exampleEntity enity to use as an example
 * @param excludedProperty array of excluded properties of the example
 * @return List<T> list of matching entities of type T
 */
@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleEntity, String[] excludedProperty) {
    Criteria criteria = createCritiera();
    Example example = Example.create(exampleEntity);

    for (String exclude : excludedProperty)
        example.excludeProperty(exclude);

    criteria.add(example);
    return criteria.list();
}

From source file:com.book.identification.dao.GenericHibernateDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String... excludeProperty) {
    Criteria crit = getSession().createCriteria(getPersistentClass());
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
        example.excludeProperty(exclude);
    }/*from  www . ja  va 2  s . c  om*/
    crit.add(example);
    return crit.list();
}

From source file:com.emergya.persistenceGeo.dao.impl.GenericHibernateDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
        example.excludeProperty(exclude);
    }/*from  w  w  w  . j  a  v a  2s  .  co  m*/
    crit.add(example);
    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.emergya.persistenceGeo.dao.impl.MultiSirDatabaseGenericHibernateDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  w w w.j  a  va 2 s . co  m
public List<T> findByExample(T exampleInstance, String[] excludedProperties, boolean ignoreCase) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    Example example = Example.create(exampleInstance);

    if (excludedProperties != null) {
        for (String exclude : excludedProperties) {
            example.excludeProperty(exclude);
        }
    }

    if (ignoreCase) {
        crit.add(example.ignoreCase());
    } else {
        crit.add(example);
    }

    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.jacobheric.youbrew.dao.impl.BaseDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
    Criteria crit = this.sessionFactory.getCurrentSession().createCriteria(this.clazz);
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
        example.excludeProperty(exclude);
    }//from   w  w  w  .  j  av a2s .c o m
    crit.add(example);
    return crit.list();
}

From source file:com.jvoid.persistence.hibernate.GenericHibernateDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*w ww .j  ava  2  s . co  m*/
public List<T> findByExample(T exampleInstance, String... excludeProperty) {
    try {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        Example example = Example.create(exampleInstance);
        for (String exclude : excludeProperty) {
            example.excludeProperty(exclude);
        }
        crit.add(example);
        return crit.list();
    } catch (Exception e) {
        // e.printStackTrace();
        getTransaction().rollback();
        return null;
    }
}