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

The following examples show how to use org.hibernate.criterion.Example#excludeProperty() . 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: HibernateUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Get a hibernate Example object that excludes zeroes values and excludes
 * all boolean -primitive and wrapper class- attributes of a given object.  
 * @param instance given object for a build a Example object.
 * @return a hibernate Example object.
 */
public static Example excludeBooleanFields (Object instance) {
	Example result = Example.create(instance).excludeZeroes();
	Set<String> fieldNames = getFieldNamesByType(instance, Boolean.class);
	fieldNames.addAll(getFieldNamesByType(instance, Boolean.TYPE));
	for (String fieldName : fieldNames) {
		result.excludeProperty(fieldName);
	}
	return result;
}