0 Replies Latest reply on Apr 30, 2008 2:35 PM by thierry accart

    Retrieving remote EntityManagerFactory from jndi (ex: for JUnit test)

    thierry accart Newbie

      Hi


      I've build a 'basic' seam project, and added an open API  - mainly DAO and tools-  to offer possibility to external tools to access it.


      The API is by default seting up the entityManager via 


      ((InjectedEntityManagerFactory) new InitialContext()
        .lookup("xxxEntityManagerFactoryName"))
        .createEntityManager());
      




      I started to build the JUnit test for my API and I'm facing a problem ... that many people are facing, without solution.



      In my JUnit test, I need to setup the EntityManager via somethting like



      Properties env = new Properties ();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
      try {
        Context ctx = new InitialContext(env);
        EntityManager em = ((InjectedEntityManagerFactory) ctx
          .lookup("java:/myprojectEntityManagerFactory"))
          .createEntityManager();     
      }
      (...)



      Of course, the JBoss server is started, EAR is deployed, and  persistence.xml sets up the java://myprojectEntityManagerFactory via


       <property 
        name="jboss.entity.manager.factory.jndi.name"
        value="java:/myprojectEntityManagerFactory" />





      Trying to retrieve the EntityManagerFactory always throws a naming exception


      javax.naming.NameNotFoundException: myprojectEntityManagerFactory not bound
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
           at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
           at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
           at javax.naming.InitialContext.lookup(InitialContext.java:351)
           at org.my.test.myprojectTest.prepare_Tests(prepare_Tests.java:48)
      



      Has anybody an idea on how to retrieve the EntityManagerFactory from remote Jboss (jnp://127.0.0.1:1099 ?)
      Any idea for a workaround to test the API ?