document auto-enabled filters

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-27 00:33:50 +02:00
parent 2ae7bf8b92
commit 55f54dfd4b
1 changed files with 15 additions and 0 deletions

View File

@ -118,6 +118,21 @@ This is completely by design and is not in any way a bug.
More than one filter may be enabled in a given session.
Alternatively, since Hibernate 6.5, a filter may be declared as `autoEnabled` in every session.
In this case, the argument to a filter parameter must be obtained from a `Supplier`.
[source,java]
----
@FilterDef(name = "ByRegion",
autoEnabled = true,
parameters = @ParamDef(name = "region", type = String.class,
resolver = RegionSupplier.class),
defaultCondition = "region = :region")
package org.hibernate.example;
----
It's not necessary to call `enableFilter()` for a filter declared `autoEnabled = true`.
[TIP]
====
When we only need to filter rows by a static condition with no parameters, we don't need a filter, since link:{doc-javadoc-url}org/hibernate/annotations/SQLRestriction.html[`@SQLRestriction`] provides a much simpler way to do that.