public class

Example

extends Object
implements Criterion
java.lang.Object
   ↳ org.hibernate.criterion.Example

Class Overview

Support for query by example.

 List results = session.createCriteria(Parent.class)
     .add( Example.create(parent).ignoreCase() )
     .createCriteria("child")
         .add( Example.create( parent.getChild() ) )
     .list();
 
"Examples" may be mixed and matched with "Expressions" in the same Criteria.

See Also

Summary

Nested Classes
interface Example.PropertySelector A strategy for choosing property values for inclusion in the query criteria  
Protected Constructors
Example(Object entity, Example.PropertySelector selector)
Public Methods
static Example create(Object entity)
Create a new instance, which includes all non-null properties by default
Example enableLike(MatchMode matchMode)
Use the "like" operator for all string-valued properties
Example enableLike()
Use the "like" operator for all string-valued properties
Example excludeNone()
Don't exclude null or zero-valued properties
Example excludeProperty(String name)
Exclude a particular named property
Example excludeZeroes()
Exclude zero-valued properties
TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
Return typed values for all parameters in the rendered SQL fragment
Example ignoreCase()
Ignore case for all string-valued properties
Example setEscapeCharacter(Character escapeCharacter)
Set escape character for "like" clause
Example setPropertySelector(Example.PropertySelector selector)
Set the property selector
String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
Render the SQL fragment
String toString()
Protected Methods
void addComponentTypedValues(String path, Object component, CompositeType type, List list, Criteria criteria, CriteriaQuery criteriaQuery)
void addPropertyTypedValue(Object value, Type type, List list)
void appendComponentCondition(String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuffer buf)
void appendPropertyCondition(String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuffer buf)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.criterion.Criterion

Protected Constructors

protected Example (Object entity, Example.PropertySelector selector)

Public Methods

public static Example create (Object entity)

Create a new instance, which includes all non-null properties by default

Returns
  • a new instance of Example

public Example enableLike (MatchMode matchMode)

Use the "like" operator for all string-valued properties

public Example enableLike ()

Use the "like" operator for all string-valued properties

public Example excludeNone ()

Don't exclude null or zero-valued properties

public Example excludeProperty (String name)

Exclude a particular named property

public Example excludeZeroes ()

Exclude zero-valued properties

public TypedValue[] getTypedValues (Criteria criteria, CriteriaQuery criteriaQuery)

Return typed values for all parameters in the rendered SQL fragment

Parameters
criteria The local criteria
criteriaQuery The overal criteria query
Returns
  • The types values (for binding)

public Example ignoreCase ()

Ignore case for all string-valued properties

public Example setEscapeCharacter (Character escapeCharacter)

Set escape character for "like" clause

public Example setPropertySelector (Example.PropertySelector selector)

Set the property selector

public String toSqlString (Criteria criteria, CriteriaQuery criteriaQuery)

Render the SQL fragment

Parameters
criteria The local criteria
criteriaQuery The overal criteria query
Returns
  • The generated SQL fragment

public String toString ()

Protected Methods

protected void addComponentTypedValues (String path, Object component, CompositeType type, List list, Criteria criteria, CriteriaQuery criteriaQuery)

protected void addPropertyTypedValue (Object value, Type type, List list)

protected void appendComponentCondition (String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuffer buf)

protected void appendPropertyCondition (String propertyName, Object propertyValue, Criteria criteria, CriteriaQuery cq, StringBuffer buf)