Annotation Type FilterDef
-
@Target({TYPE,PACKAGE}) @Retention(RUNTIME) @Repeatable(FilterDefs.class) public @interface FilterDef
Declares a filter, specifying its name(), optionally, a default condition, and its parameter names and types, if it has parameters.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 usingFilter.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
Session.enableFilter(String)
, passing the name of the filter, and then setting its parameters.session.enableFilter("Current");
A filter has no effect unless it is explicitly enabled.
- See Also:
Filter
,DialectOverride.FilterDefs
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
autoEnabled
The flag used to auto-enable the filter on the session.String
defaultCondition
The default filter condition, a SQL expression used for filtering the rows returned by a query when the filter is enabled.ParamDef[]
parameters
The names and types of the parameters of the filter.
-
-
-
Element Detail
-
name
String name
The name of the declared filter. Must be unique within a persistence unit.- See Also:
SessionFactory.getDefinedFilterNames()
-
-
-
defaultCondition
String defaultCondition
The 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[] parameters
The names and types of the parameters of the filter.- Default:
- {}
-
-