Skip to content

Commit ea96632

Browse files
vladmihalceagbadner
authored andcommitted
HHH-2123 - clarification on the way interceptors and event system interact.
(cherry picked from commit d126faa)
1 parent 8d50d56 commit ea96632

File tree

1 file changed

+14
-1
lines changed
  • documentation/src/main/asciidoc/userguide/chapters/events

1 file changed

+14
-1
lines changed

documentation/src/main/asciidoc/userguide/chapters/events/Events.adoc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,30 @@ The listeners should be considered stateless; they are shared between requests,
7272

7373
A custom listener implements the appropriate interface for the event it wants to process and/or extend one of the convenience base classes
7474
(or even the default event listeners used by Hibernate out-of-the-box as these are declared non-final for this purpose).
75+
7576
Here is an example of a custom load event listener:
7677

7778
[[events-interceptors-load-listener-example]]
78-
.Custom LoadListener example
79+
.Custom `LoadListener` example
7980
====
8081
[source, JAVA, indent=0]
8182
----
8283
include::{sourcedir}/ListenerTest.java[tags=events-interceptors-load-listener-example]
8384
----
8485
====
8586

87+
[[events-mixing-events-and-interceptors]]
88+
=== Mixing Events and Interceptors
89+
90+
When you want to customize the entity state transition behavior, you have to options:
91+
92+
. you provide a custom `Interceptor`, which is taken into consideration by the default Hibernate event listeners.
93+
For example, the `Interceptor#onSave()` method is invoked by Hibernate `AbstractSaveEventListener`.
94+
Or, the `Interceptor#onLoad()` is called by the `DefaultPreLoadEventListener`.
95+
. you can replace any given default event listener with your own implementation.
96+
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.
97+
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.
98+
8699
[[events-declarative-security]]
87100
=== Hibernate declarative security
88101

0 commit comments

Comments
 (0)