-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Getting Session or EntityManager inside interceptor
PostPosted: Sun Oct 12, 2008 1:56 pm 
Newbie

Joined: Fri Oct 05, 2007 3:27 am
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.