Can you access EntityManagers from EntityListeners?

☆樱花仙子☆ 提交于 2019-12-05 17:18:06
Arthur Ronald F D Garcia

In fact, you are right. JPA specification says it and, in that case, it suggests EJB listeners (or Spring AOP in non-Java EE environment) instead.

I do not know the purporse of your listener. But only put cross-cutting concerns like logging, authentication, and routing inside it. Hibernate reference documentation, for instance, uses listeners in order to audit log of all object modifications. It could be done by EJB listeners (or Spring AOP in non-Java EE environment) once EJB listeners can use entity manager. Java EE specification allows it. Therefore, EJB listeners share the the same ENC used by its target EJB and, this way, also share the same persistence context (entity manager).

If you wish, see my profile. I have many ORM related issues.

regards,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!