Annotation 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 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:

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the declared filter.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    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 call SharedSessionContract.enableFilter(String).
    The default filter condition, a SQL expression used for filtering the rows returned by a query when the filter is enabled.
    The names and types of the parameters of the filter.
  • Element Details

    • 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 using Filter.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:
      {}
    • autoEnabled

      boolean autoEnabled
      Specifies that the filter auto-enabled, so that it is not necessary to call SharedSessionContract.enableFilter(String).

      Arguments to parameters() of auto-enabled filters are supplied via ParamDef.resolver().

      Default:
      false
    • applyToLoadByKey

      @Incubating boolean 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