-->
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: How to lookup the (propagated?) persistence context
PostPosted: Thu Oct 09, 2008 11:46 am 
Newbie

Joined: Fri Dec 29, 2006 5:56 am
Posts: 4
Location: Copenhagen, Denmark, Europe
Hi,

From the documentation I seems that I should be able get access to the session of container managed entity manager.

http://www.hibernate.org/hib_docs/entit ... cture.html

So I would like to try this in my EJB3 app on JBoss 4.2. So now I have a Session bean with

Code:
   @PersistenceContext(unitName = "tacs") @Inject EntityManager entityManager;
[...]
   public void test(Cpe cpe){      
      System.out.println("Transaction in EJB " + entityManager.getDelegate().hashCode() );      
      cpe.getMatch();   
   }


and Cpe has

Code:
   public static EntityManagerFactory getEntityManagerFactory() {
        EntityManagerFactory entityManagerFactory = null;
        try {               
                entityManagerFactory =  (EntityManagerFactory)(new InitialContext()).lookup("java:/tacsEntityManagerFactory");
        } catch(NamingException e) { }
        return entityManagerFactory;
   }
   
   public static Session getSession(){
      EntityManager entityManager = getEntityManagerFactory().createEntityManager();      
      return (org.hibernate.Session) entityManager.getDelegate();
   }   
   
   public void getMatch(){
      System.out.println("With transaction " + getSession().hashCode() );
   }


The hashcodes are not the same. Should they be?

I would like to be able to lookup the entitymanager/session, so that I dont have to pass i around as a parameter.

Best,
Anders


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.