Skip to content

Commit

Permalink
HHH-2123 - clarification on the way interceptors and event system int…
Browse files Browse the repository at this point in the history
…eract.

(cherry picked from commit d126faa)
  • Loading branch information
vladmihalcea authored and gbadner committed Feb 15, 2017
1 parent 03629b6 commit 517877f
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -72,17 +72,30 @@ 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
(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:

[[events-interceptors-load-listener-example]]
.Custom LoadListener example
.Custom `LoadListener` example
====
[source, JAVA, indent=0]
----
include::{sourcedir}/ListenerTest.java[tags=events-interceptors-load-listener-example]
----
====

[[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]]
=== Hibernate declarative security

Expand Down

0 comments on commit 517877f

Please sign in to comment.