---
title: "Hibernate  Example.setPropertySelector"
author: "side91"
date: "2009-08-24T10:33:03Z"
tags: []
slug: "hibernate-example-setpropertyselector"
draft: false
lastmod: "2009-08-24T10:33:03Z"
id: 456190
url: "https://side91.iteye.com/blog/456190"
---

MyPropertySelector


```java

package util;

import org.hibernate.criterion.Example.PropertySelector;
import org.hibernate.type.Type;

@SuppressWarnings("serial")
public class MyPropertySelector {
	private static PropertySelector NOT_NULL_BLANK_ZEROS = null;
	
	private MyPropertySelector(){
	}

	public static PropertySelector getNotNullBlankZeros() {
		if(NOT_NULL_BLANK_ZEROS == null){
		   NOT_NULL_BLANK_ZEROS = new PropertySelector() {
				public boolean include(Object value, String propertyName, Type type) {
					return value != null
							&& (((value instanceof String) && !("").equals(value)) 
									|| ((value instanceof Number) && ((Number) value).longValue() != 0));			
				}
			};
		}
		return NOT_NULL_BLANK_ZEROS;
	}

}

```




```java

Criteria c = session.createCriteria(Student.class);
l = c.add(Example.create(s)
                 .setPropertySelector(

	            MyPropertySelector.getNotNullBlankZeros())

                 .enableLike()
).list()

```