-->
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: accessing an EntityManager from within an Entity
PostPosted: Tue Sep 08, 2009 5:26 am 
Newbie

Joined: Tue Sep 08, 2009 5:16 am
Posts: 1
Hi,

I am working in a container managed enviroment accessing interacting with entities
via stateless session beans. I am injecting the PersistenceContext in the standard JEE way
within the stateless session bean. I have made my entityManager available via JNDI.

My question is whether is legal to have methods on my entity which gain a reference to
an entityManager via a JNDI lookup. I then perform named queries.

If so, will the entityManager be the same one injected by by the stateless session bean?

The example method is

Code:
    @Transient
    public Address getCurrentAddress()
    {
        try
        {
            Context ctx = new InitialContext();
            EntityManager em = (EntityManager) ctx.lookup(ENTITY_MANAGER_JNDI_NAME);
            return (Address)em.createNamedQuery("aNamedQuery").getSingleResult();
         }
         catch( NamingException e )
         {
              throw new RuntimeException( e );
         }
    }


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.