-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to instantiate a single EntityManager in an interceptor?
PostPosted: Mon Apr 28, 2008 12:47 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

I'm using:
hibernate-3.2.6.GA
hibernate-entitymanager-3.3.2.GA

How to instantiate a single EntityManager in an interceptor?

Hibernate's OpenSession() method does take parameter of type "Interceptor", but createEntityManager() doesn't.

Please advise.

Below is the code for interceptor. I'm trying to convert HibernateUtil so that I can use JPA EntityManagerFactory and EntityManager. In HibernateUtil, I instantiate like below. But don't know how when come to createEntityeManager
Code:
s = getSessionFactory().openSession(getInterceptor());


Code:
   /**
    * Register a Hibernate interceptor with the current thread.
    * <p>
    * Every Session opened is opened with this interceptor after
    * registration. Has no effect if the current Session of the
    * thread is already open, effective on next close()/getSession().
    */
   public static void registerInterceptor(Interceptor interceptor) {
      threadInterceptor.set(interceptor);
   }

   private static Interceptor getInterceptor() {
      Interceptor interceptor =
         (Interceptor) threadInterceptor.get();
      return interceptor;
   }


Regards,
Jap.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 2:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Interceptors are really a Hibernate specific feature and not part of JPA. Hence, there is no way to specify an interceptor in EnitityManagerFactory. However, you can add the property hibernate.ejb.interceptor to your persistence.xml and specify a shared interceptor. This interceptor must be thread safe though. Check the Hibernate EntityManager documentation.

There are probably other solutions to your problem as depending on what you want to achieve.

--Hardy


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

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.