Annotation Interface FilterDef
Every entity or collection which is affected by a named filter
declared using this annotation must be explicitly annotated
@Filter
, and the name of this filter definition
must be given. The @Filter
annotation may override the default condition specified by this
annotation using Filter.condition()
.
For example, if a filter is declared as follows:
@FilterDef(name = "Current", defaultCondition = "status<>'DELETED'") package org.hibernate.domain;
Then the filter may be applied to an entity type like this:
@Entity @Filter(name = "Current") class Record { @Id @GeneratedValue Long id; @Enumerated(STRING) Status status; ... }
At runtime, a filter may be enabled in a particular session by
calling SharedSessionContract.enableFilter(String)
,
passing the name of the filter, and then supplying arguments to
its parameters.
session.enableFilter("Current");
A filter has no effect unless:
- it is explicitly enabled by calling
enableFilter
, or - it is declared
autoEnabled = true
.
- See Also:
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionboolean
Specifies that the filter should be applied to operations which fetch an entity by its identifier.boolean
Specifies that the filter auto-enabled, so that it is not necessary to callSharedSessionContract.enableFilter(String)
.The default filter condition, a SQL expression used for filtering the rows returned by a query when the filter is enabled.ParamDef[]
The names and types of the parameters of the filter.
-
Element Details
-
name
String nameThe name of the declared filter. Must be unique within a persistence unit.- See Also:
-
-
-
defaultCondition
String defaultConditionThe default filter condition, a SQL expression used for filtering the rows returned by a query when the filter is enabled. This default condition may be overridden by any entity or collection to which the filter applies usingFilter.condition()
.If every entity and collection to which the filter applies explicitly specifies its own filter condition, then the default condition is unnecessary, and so this member is optional.
- Default:
- ""
-
parameters
ParamDef[] parametersThe names and types of the parameters of the filter.- Default:
- {}
-
autoEnabled
boolean autoEnabledSpecifies that the filter auto-enabled, so that it is not necessary to callSharedSessionContract.enableFilter(String)
.Arguments to parameters() of auto-enabled filters are supplied via
ParamDef.resolver()
.- Default:
- false
-
applyToLoadByKey
Specifies that the filter should be applied to operations which fetch an entity by its identifier.By default, a filter does not apply to lookups by primary key, for example, when:
If the effect of a filter with
applyToLoadByKey = true
would be to nullify a to-one association,EntityFilterException
is thrown.- Default:
- false
-