1 Reply Latest reply on Oct 11, 2011 2:57 AM by jaikiran pai

    Lookup for EntityManager

    vamshi appala Newbie

      I have created an EAR which has EJBS and entities. In one of the session bean I am calling Hibernate validator class  which requires EntityManager. In case of JBOSS 6 I have used the Intialcontex.lookp("java:/comp/em) to get the entitymanager.How can I acheive the similar functionality in jboss 7

       

       

         public EntityManager getEntityManager() throws Exception {

       

              InitialContext ctx;

              try {

                  ctx = new InitialContext();

                  return (EntityManager) ctx.lookup("java:comp/env/em");

              }

              catch (NamingException e) {

                  // This is critical internal issue and it is not probably to see in case of proper deployment. So no translation for message applied.

                  String errMsg = "Could not acquire EntityManager from bean context. Reason: " + e.getMessage();

                  log.error(errMsg);

                  throw new Exception(errMsg);

              }

          }