Top Description Constructors Methods
org.hibernate.criterion

public Class Restrictions

extends Object
Class Inheritance
Known Direct Subclasses
org.hibernate.criterion.Expression
Imports
java.util.Collection, .Map, org.hibernate.type.Type

The criterion package may be used by applications as a framework for building new kinds of Criterion. However, it is intended that most applications will simply use the built-in criterion types via the static factory methods of this class. See also the Projections factory methods for generating Projection instances
Authors
Gavin King, Steve Ebersole
See Also
org.hibernate.Criteria

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static Criterion

Returns:

Criterion
allEq
(Map<String, ?>
a map from property names to values
propertyNameValues
)

Apply an "equals" constraint to each property in the key set of a Map

public static LogicalExpression

Returns:

The Criterion
and
(Criterion
One expression
lhs
,
Criterion
The other expression
rhs
)

Return the conjunction of two expressions

public static Conjunction

Returns:

The conjunction
and
(Criterion...
The predicates making up the initial junction
predicates
)

Return the conjunction of multiple expressions

public static Criterion

Returns:

The Criterion
between
(String
The name of the property
propertyName
,
Object
The low value
low
,
Object
The high value
high
)

Apply a "between" constraint to the named property

public static Conjunction

Returns:

Conjunction
conjunction
()

Group expressions together in a single conjunction (A and B and C...).

public static Conjunction

Returns:

Conjunction
conjunction
(Criterion...
The initial set of conditions to put into the Conjunction
conditions
)

Group expressions together in a single conjunction (A and B and C...).

public static Disjunction

Returns:

Conjunction
disjunction
()

Group expressions together in a single disjunction (A or B or C...).

public static Disjunction

Returns:

Conjunction
disjunction
(Criterion...
The initial set of conditions to put into the Disjunction
conditions
)

Group expressions together in a single disjunction (A or B or C...).

public static SimpleExpression

Returns:

SimpleExpression
eq
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply an "equal" constraint to the named property

public static Criterion

Returns:

The Criterion
eqOrIsNull
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply an "equal" constraint to the named property.

public static PropertyExpression

Returns:

The Criterion
eqProperty
(String
One property name
propertyName
,
String
The other property name
otherPropertyName
)

Apply an "equal" constraint to two properties

public static Criterion
fkEq(String associationPropertyName, Object value)

public static Criterion
fkIsNotNull(String associationPropertyName)

public static Criterion
fkIsNull(String associationPropertyName)

public static Criterion
fkNe(String associationPropertyName, Object value)

public static SimpleExpression

Returns:

The Criterion
ge
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "greater than or equal" constraint to the named property

public static PropertyExpression

Returns:

The Criterion
geProperty
(String
One property name
propertyName
,
String
The other property name
otherPropertyName
)

Apply a "greater than or equal" constraint to two properties

public static SimpleExpression

Returns:

The Criterion
gt
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "greater than" constraint to the named property

public static PropertyExpression

Returns:

The Criterion
gtProperty
(String
One property name
propertyName
,
String
The other property name
otherPropertyName
)

Apply a "greater than" constraint to two properties

public static Criterion

Returns:

Criterion
idEq
(Object
The value to use in comparison
value
)

Apply an "equal" constraint to the identifier property

public static Criterion

Returns:

The Criterion
ilike
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

A case-insensitive "like" (similar to Postgres ilike operator)

public static Criterion

Returns:

The Criterion
ilike
(String
The name of the property
propertyName
,
String
The value to use in comparison
value
,
MatchMode
The match mode to use in comparison
matchMode
)

A case-insensitive "like" (similar to Postgres ilike operator) using the provided match mode

public static Criterion

Returns:

The Criterion
in
(String
The name of the property
propertyName
,
Object...
The literal values to use in the IN restriction
values
)

Apply an "in" constraint to the named property.

public static Criterion

Returns:

The Criterion
in
(String
The name of the property
propertyName
,
Collection<E>
The literal values to use in the IN restriction
values
)

Apply an "in" constraint to the named property.

public static Criterion

Returns:

The Criterion
isEmpty
(String
The name of the collection property
propertyName
)

Constrain a collection valued property to be empty

public static Criterion

Returns:

The Criterion
isNotEmpty
(String
The name of the collection property
propertyName
)

Constrain a collection valued property to be non-empty

public static Criterion

Returns:

The Criterion
isNotNull
(String
The property name
propertyName
)

Apply an "is not null" constraint to the named property

public static Criterion

Returns:

Criterion
isNull
(String
The name of the property
propertyName
)

Apply an "is null" constraint to the named property

public static SimpleExpression

Returns:

The Criterion
le
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "less than or equal" constraint to the named property

public static PropertyExpression

Returns:

The Criterion
leProperty
(String
One property name
propertyName
,
String
The other property name
otherPropertyName
)

Apply a "less than or equal" constraint to two properties

public static SimpleExpression

Returns:

The Criterion
like
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "like" constraint to the named property

public static SimpleExpression

Returns:

The Criterion
like
(String
The name of the property
propertyName
,
String
The value to use in comparison
value
,
MatchMode
The match mode to use in comparison
matchMode
)

Apply a "like" constraint to the named property using the provided match mode

public static SimpleExpression

Returns:

The Criterion
lt
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "less than" constraint to the named property

public static PropertyExpression

Returns:

The Criterion
ltProperty
(String
One property name
propertyName
,
String
The other property name
otherPropertyName
)

Apply a "less than" constraint to two properties

public static NaturalIdentifier

Returns:

The Criterion
naturalId
()

Consider using any of the natural id based loading stuff from session instead, especially in cases where the restriction is the full set of natural id values.

public static SimpleExpression

Returns:

The Criterion
ne
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "not equal" constraint to the named property

public static Criterion

Returns:

The Criterion
neOrIsNotNull
(String
The name of the property
propertyName
,
Object
The value to use in comparison
value
)

Apply a "not equal" constraint to the named property.

public static PropertyExpression

Returns:

The Criterion
neProperty
(String
One property name
propertyName
,
String
The other property name
otherPropertyName
)

Apply a "not equal" constraint to two properties

public static Criterion

Returns:

Criterion
not
(Criterion
The expression to be negated
expression
)

Return the negation of an expression

public static LogicalExpression

Returns:

The Criterion
or
(Criterion
One expression
lhs
,
Criterion
The other expression
rhs
)

Return the disjunction of two expressions

public static Disjunction

Returns:

The conjunction
or
(Criterion...
The predicates making up the initial junction
predicates
)

Return the disjunction of multiple expressions

public static Criterion

Returns:

The Criterion
sizeEq
(String
The name of the collection property
propertyName
,
int
The size to use in comparison
size
)

Constrain a collection valued property by size

public static Criterion

Returns:

The Criterion
sizeGe
(String
The name of the collection property
propertyName
,
int
The size to use in comparison
size
)

Constrain a collection valued property by size

public static Criterion

Returns:

The Criterion
sizeGt
(String
The name of the collection property
propertyName
,
int
The size to use in comparison
size
)

Constrain a collection valued property by size

public static Criterion

Returns:

The Criterion
sizeLe
(String
The name of the collection property
propertyName
,
int
The size to use in comparison
size
)

Constrain a collection valued property by size

public static Criterion

Returns:

The Criterion
sizeLt
(String
The name of the collection property
propertyName
,
int
The size to use in comparison
size
)

Constrain a collection valued property by size

public static Criterion

Returns:

The Criterion
sizeNe
(String
The name of the collection property
propertyName
,
int
The size to use in comparison
size
)

Constrain a collection valued property by size

public static Criterion

Returns:

The Criterion
sqlRestriction
(String
The SQL restriction
sql
,
Object[]
The parameter values
values
,
Type[]
The parameter types
types
)

Create a restriction expressed in SQL with JDBC parameters.

public static Criterion

Returns:

The Criterion
sqlRestriction
(String
The SQL restriction
sql
,
Object
The parameter value
value
,
Type
The parameter type
type
)

Create a restriction expressed in SQL with one JDBC parameter.

public static Criterion

Returns:

The Criterion
sqlRestriction
(String
The SQL restriction
sql
)

Apply a constraint expressed in SQL with no JDBC parameters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Restrictionsback to summary
protected Restrictions()

Method Detail

allEqback to summary
public static Criterion allEq(Map<String, ?> propertyNameValues)

Apply an "equals" constraint to each property in the key set of a Map

Parameters
propertyNameValues:Map<String, ?>

a map from property names to values

Returns:Criterion

Criterion

Annotations
@SuppressWarnings:UnusedDeclaration
See Also
Conjunction
andback to summary
public static LogicalExpression and(Criterion lhs, Criterion rhs)

Return the conjunction of two expressions

Parameters
lhs:Criterion

One expression

rhs:Criterion

The other expression

Returns:LogicalExpression

The Criterion

andback to summary
public static Conjunction and(Criterion... predicates)

Return the conjunction of multiple expressions

Parameters
predicates:Criterion[]

The predicates making up the initial junction

Returns:Conjunction

The conjunction

betweenback to summary
public static Criterion between(String propertyName, Object low, Object high)

Apply a "between" constraint to the named property

Parameters
propertyName:String

The name of the property

low:Object

The low value

high:Object

The high value

Returns:Criterion

The Criterion

See Also
BetweenExpression
conjunctionback to summary
public static Conjunction conjunction()

Group expressions together in a single conjunction (A and B and C...). This form creates an empty conjunction. See Conjunction#add(Criterion)

Returns:Conjunction

Conjunction

conjunctionback to summary
public static Conjunction conjunction(Criterion... conditions)

Group expressions together in a single conjunction (A and B and C...).

Parameters
conditions:Criterion[]

The initial set of conditions to put into the Conjunction

Returns:Conjunction

Conjunction

disjunctionback to summary
public static Disjunction disjunction()

Group expressions together in a single disjunction (A or B or C...). This form creates an empty disjunction. See Disjunction#add(Criterion)

Returns:Disjunction

Conjunction

disjunctionback to summary
public static Disjunction disjunction(Criterion... conditions)

Group expressions together in a single disjunction (A or B or C...).

Parameters
conditions:Criterion[]

The initial set of conditions to put into the Disjunction

Returns:Disjunction

Conjunction

eqback to summary
public static SimpleExpression eq(String propertyName, Object value)

Apply an "equal" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

SimpleExpression

See Also
SimpleExpression
eqOrIsNullback to summary
public static Criterion eqOrIsNull(String propertyName, Object value)

Apply an "equal" constraint to the named property. If the value is null, instead apply "is null".

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:Criterion

The Criterion

See Also
eq, isNull
eqPropertyback to summary
public static PropertyExpression eqProperty(String propertyName, String otherPropertyName)

Apply an "equal" constraint to two properties

Parameters
propertyName:String

One property name

otherPropertyName:String

The other property name

Returns:PropertyExpression

The Criterion

See Also
PropertyExpression
fkEqback to summary
public static Criterion fkEq(String associationPropertyName, Object value)
fkIsNotNullback to summary
public static Criterion fkIsNotNull(String associationPropertyName)
fkIsNullback to summary
public static Criterion fkIsNull(String associationPropertyName)
fkNeback to summary
public static Criterion fkNe(String associationPropertyName, Object value)
geback to summary
public static SimpleExpression ge(String propertyName, Object value)

Apply a "greater than or equal" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
gePropertyback to summary
public static PropertyExpression geProperty(String propertyName, String otherPropertyName)

Apply a "greater than or equal" constraint to two properties

Parameters
propertyName:String

One property name

otherPropertyName:String

The other property name

Returns:PropertyExpression

The Criterion

See Also
PropertyExpression
gtback to summary
public static SimpleExpression gt(String propertyName, Object value)

Apply a "greater than" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
gtPropertyback to summary
public static PropertyExpression gtProperty(String propertyName, String otherPropertyName)

Apply a "greater than" constraint to two properties

Parameters
propertyName:String

One property name

otherPropertyName:String

The other property name

Returns:PropertyExpression

The Criterion

See Also
PropertyExpression
idEqback to summary
public static Criterion idEq(Object value)

Apply an "equal" constraint to the identifier property

Parameters
value:Object

The value to use in comparison

Returns:Criterion

Criterion

See Also
IdentifierEqExpression
ilikeback to summary
public static Criterion ilike(String propertyName, Object value)

A case-insensitive "like" (similar to Postgres ilike operator)

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:Criterion

The Criterion

See Also
LikeExpression
ilikeback to summary
public static Criterion ilike(String propertyName, String value, MatchMode matchMode)

A case-insensitive "like" (similar to Postgres ilike operator) using the provided match mode

Parameters
propertyName:String

The name of the property

value:String

The value to use in comparison

matchMode:MatchMode

The match mode to use in comparison

Returns:Criterion

The Criterion

See Also
LikeExpression
inback to summary
public static Criterion in(String propertyName, Object... values)

Apply an "in" constraint to the named property.

Parameters
propertyName:String

The name of the property

values:Object[]

The literal values to use in the IN restriction

Returns:Criterion

The Criterion

See Also
InExpression
inback to summary
public static Criterion in(String propertyName, Collection<E> values)

Apply an "in" constraint to the named property.

Parameters
propertyName:String

The name of the property

values:Collection<E>

The literal values to use in the IN restriction

Returns:Criterion

The Criterion

See Also
InExpression
isEmptyback to summary
public static Criterion isEmpty(String propertyName)

Constrain a collection valued property to be empty

Parameters
propertyName:String

The name of the collection property

Returns:Criterion

The Criterion

See Also
EmptyExpression
isNotEmptyback to summary
public static Criterion isNotEmpty(String propertyName)

Constrain a collection valued property to be non-empty

Parameters
propertyName:String

The name of the collection property

Returns:Criterion

The Criterion

See Also
NotEmptyExpression
isNotNullback to summary
public static Criterion isNotNull(String propertyName)

Apply an "is not null" constraint to the named property

Parameters
propertyName:String

The property name

Returns:Criterion

The Criterion

See Also
NotNullExpression
isNullback to summary
public static Criterion isNull(String propertyName)

Apply an "is null" constraint to the named property

Parameters
propertyName:String

The name of the property

Returns:Criterion

Criterion

See Also
NullExpression
leback to summary
public static SimpleExpression le(String propertyName, Object value)

Apply a "less than or equal" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
lePropertyback to summary
public static PropertyExpression leProperty(String propertyName, String otherPropertyName)

Apply a "less than or equal" constraint to two properties

Parameters
propertyName:String

One property name

otherPropertyName:String

The other property name

Returns:PropertyExpression

The Criterion

See Also
PropertyExpression
likeback to summary
public static SimpleExpression like(String propertyName, Object value)

Apply a "like" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
likeback to summary
public static SimpleExpression like(String propertyName, String value, MatchMode matchMode)

Apply a "like" constraint to the named property using the provided match mode

Parameters
propertyName:String

The name of the property

value:String

The value to use in comparison

matchMode:MatchMode

The match mode to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
ltback to summary
public static SimpleExpression lt(String propertyName, Object value)

Apply a "less than" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
ltPropertyback to summary
public static PropertyExpression ltProperty(String propertyName, String otherPropertyName)

Apply a "less than" constraint to two properties

Parameters
propertyName:String

One property name

otherPropertyName:String

The other property name

Returns:PropertyExpression

The Criterion

See Also
PropertyExpression
naturalIdback to summary
public static NaturalIdentifier naturalId()

Consider using any of the natural id based loading stuff from session instead, especially in cases where the restriction is the full set of natural id values.

Returns:NaturalIdentifier

The Criterion

See Also
NaturalIdentifier, org.hibernate.Session#byNaturalId(Class), org.hibernate.Session#byNaturalId(String), org.hibernate.Session#bySimpleNaturalId(Class), org.hibernate.Session#bySimpleNaturalId(String)
neback to summary
public static SimpleExpression ne(String propertyName, Object value)

Apply a "not equal" constraint to the named property

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:SimpleExpression

The Criterion

See Also
SimpleExpression
neOrIsNotNullback to summary
public static Criterion neOrIsNotNull(String propertyName, Object value)

Apply a "not equal" constraint to the named property. If the value is null, instead apply "is not null".

Parameters
propertyName:String

The name of the property

value:Object

The value to use in comparison

Returns:Criterion

The Criterion

See Also
ne, isNotNull
nePropertyback to summary
public static PropertyExpression neProperty(String propertyName, String otherPropertyName)

Apply a "not equal" constraint to two properties

Parameters
propertyName:String

One property name

otherPropertyName:String

The other property name

Returns:PropertyExpression

The Criterion

See Also
PropertyExpression
notback to summary
public static Criterion not(Criterion expression)

Return the negation of an expression

Parameters
expression:Criterion

The expression to be negated

Returns:Criterion

Criterion

See Also
NotExpression
orback to summary
public static LogicalExpression or(Criterion lhs, Criterion rhs)

Return the disjunction of two expressions

Parameters
lhs:Criterion

One expression

rhs:Criterion

The other expression

Returns:LogicalExpression

The Criterion

orback to summary
public static Disjunction or(Criterion... predicates)

Return the disjunction of multiple expressions

Parameters
predicates:Criterion[]

The predicates making up the initial junction

Returns:Disjunction

The conjunction

sizeEqback to summary
public static Criterion sizeEq(String propertyName, int size)

Constrain a collection valued property by size

Parameters
propertyName:String

The name of the collection property

size:int

The size to use in comparison

Returns:Criterion

The Criterion

See Also
SizeExpression
sizeGeback to summary
public static Criterion sizeGe(String propertyName, int size)

Constrain a collection valued property by size

Parameters
propertyName:String

The name of the collection property

size:int

The size to use in comparison

Returns:Criterion

The Criterion

Annotations
@SuppressWarnings:UnusedDeclaration
See Also
SizeExpression
sizeGtback to summary
public static Criterion sizeGt(String propertyName, int size)

Constrain a collection valued property by size

Parameters
propertyName:String

The name of the collection property

size:int

The size to use in comparison

Returns:Criterion

The Criterion

Annotations
@SuppressWarnings:UnusedDeclaration
See Also
SizeExpression
sizeLeback to summary
public static Criterion sizeLe(String propertyName, int size)

Constrain a collection valued property by size

Parameters
propertyName:String

The name of the collection property

size:int

The size to use in comparison

Returns:Criterion

The Criterion

Annotations
@SuppressWarnings:UnusedDeclaration
See Also
SizeExpression
sizeLtback to summary
public static Criterion sizeLt(String propertyName, int size)

Constrain a collection valued property by size

Parameters
propertyName:String

The name of the collection property

size:int

The size to use in comparison

Returns:Criterion

The Criterion

Annotations
@SuppressWarnings:UnusedDeclaration
See Also
SizeExpression
sizeNeback to summary
public static Criterion sizeNe(String propertyName, int size)

Constrain a collection valued property by size

Parameters
propertyName:String

The name of the collection property

size:int

The size to use in comparison

Returns:Criterion

The Criterion

Annotations
@SuppressWarnings:UnusedDeclaration
See Also
SizeExpression
sqlRestrictionback to summary
public static Criterion sqlRestriction(String sql, Object[] values, Type[] types)

Create a restriction expressed in SQL with JDBC parameters. Any occurrences of {alias} will be replaced by the table alias.

Parameters
sql:String

The SQL restriction

values:Object[]

The parameter values

types:Type[]

The parameter types

Returns:Criterion

The Criterion

See Also
SQLCriterion
sqlRestrictionback to summary
public static Criterion sqlRestriction(String sql, Object value, Type type)

Create a restriction expressed in SQL with one JDBC parameter. Any occurrences of {alias} will be replaced by the table alias.

Parameters
sql:String

The SQL restriction

value:Object

The parameter value

type:Type

The parameter type

Returns:Criterion

The Criterion

See Also
SQLCriterion
sqlRestrictionback to summary
public static Criterion sqlRestriction(String sql)

Apply a constraint expressed in SQL with no JDBC parameters. Any occurrences of {alias} will be replaced by the table alias.

Parameters
sql:String

The SQL restriction

Returns:Criterion

The Criterion

See Also
SQLCriterion