mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-07 03:38:16 +00:00
HHH-2123 - clarification on the way interceptors and event system interact.
(cherry picked from commit d126faa7d92725399a876005880db7816faefe0d)
This commit is contained in:
parent
8d50d567ac
commit
ea96632ca1
@ -72,10 +72,11 @@ The listeners should be considered stateless; they are shared between requests,
|
|||||||
|
|
||||||
A custom listener implements the appropriate interface for the event it wants to process and/or extend one of the convenience base classes
|
A custom listener implements the appropriate interface for the event it wants to process and/or extend one of the convenience base classes
|
||||||
(or even the default event listeners used by Hibernate out-of-the-box as these are declared non-final for this purpose).
|
(or even the default event listeners used by Hibernate out-of-the-box as these are declared non-final for this purpose).
|
||||||
|
|
||||||
Here is an example of a custom load event listener:
|
Here is an example of a custom load event listener:
|
||||||
|
|
||||||
[[events-interceptors-load-listener-example]]
|
[[events-interceptors-load-listener-example]]
|
||||||
.Custom LoadListener example
|
.Custom `LoadListener` example
|
||||||
====
|
====
|
||||||
[source, JAVA, indent=0]
|
[source, JAVA, indent=0]
|
||||||
----
|
----
|
||||||
@ -83,6 +84,18 @@ include::{sourcedir}/ListenerTest.java[tags=events-interceptors-load-listener-ex
|
|||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
|
||||||
|
[[events-mixing-events-and-interceptors]]
|
||||||
|
=== Mixing Events and Interceptors
|
||||||
|
|
||||||
|
When you want to customize the entity state transition behavior, you have to options:
|
||||||
|
|
||||||
|
. you provide a custom `Interceptor`, which is taken into consideration by the default Hibernate event listeners.
|
||||||
|
For example, the `Interceptor#onSave()` method is invoked by Hibernate `AbstractSaveEventListener`.
|
||||||
|
Or, the `Interceptor#onLoad()` is called by the `DefaultPreLoadEventListener`.
|
||||||
|
. you can replace any given default event listener with your own implementation.
|
||||||
|
When doing this, you should probably extend the default listeners because otherwise you'd have to take care of all the low-level entity state transition logic.
|
||||||
|
For example, if you replace the `DefaultPreLoadEventListener` with your own implementation, then, only if you call the `Interceptor#onLoad()` method explicitly, you can mix the custom load event listener with a custom Hibernate interceptor.
|
||||||
|
|
||||||
[[events-declarative-security]]
|
[[events-declarative-security]]
|
||||||
=== Hibernate declarative security
|
=== Hibernate declarative security
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user