Java Code Examples for org.hibernate.criterion.Example#create()

The following examples show how to use org.hibernate.criterion.Example#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericHibernateDAO.java    From jVoiD with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
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;
	}
}
 
Example 2
Source File: SoapboxDao.java    From soapbox-race with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<ISoapBoxEntity> find(ISoapBoxEntity entity) {
	EntityManager manager = ConnectionDB.getManager();
	manager.clear();
	Session sessao = (Session) manager.getDelegate();
	Example example = Example.create(entity);
	example.excludeZeroes();
	Criteria criteria = sessao.createCriteria(entity.getClass());
	criteria.add(example);
	return criteria.list();
}