You are actually right. JPA talks about this, and in this case, it offers listeners EJB (or Spring AOP in an environment other than Java EE).
I do not know the purple of your listener. But just pose cross-cutting issues such as logging, authentication, and routing within it. For example, the Hibernate help documentation uses listeners to audit the log of all object modifications. This can be done by EJB listeners (or Spring AOP in a non-Java EE environment) when EJB listeners can use entity manager. The Java EE specification allows this. Therefore, EJB listeners use the same ENC used by the target EJB, and thus also use the same persistence context (entity manager).
If you want, see my profile. I have many problems related to ORM.
Yours faithfully,
source share