Hello,
I have searched this forum and googled around and I have found many questions but not a single answer to this question: "How to get Session or EntityManager inside interceptor in managed environments".
The typical use case is an audit interceptor that should persist changes to entities. Interceptors are perfect to capture the changes, but the problem is how to get a Session or EntityManager inside the interceptor in managed environments.
I have tried to create a separate persistence context and created EntityManagerFactory for it in Interceptor constructor. How ever, if the context is JTA context it can not be created (complains that this type of entity manager factory needs JTA context), and if I make the context RESOURCE_LOCAL I'll end up using different transaction for auditing and this, IMHO is really dangerous (other could be rolledback while other is committed).
I have worked around the problem by obtaining the DataSource from JNDI and using plain JDBC. Not very elegant.
Is it really so that nobody has any ideas how to solve this?
--
-jarppe
|