6 Replies Latest reply on Apr 18, 2006 7:37 PM by onewnan

    Error when runnig the embeddable-test-with-unit - EJB3-ALPHA

      Hi all ejb3 gurus,

      When I try to run the Test class EmbeddedEjb3TestCase.java i get this NameNotFoundException

      javax.naming.NameNotFoundException: EntityManagers not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at de.mathema.junit.EmbeddedEjb3Test.testEntityManager(EmbeddedEjb3Test.java:54)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      


      I suppose that i have to inject in embedded-jboss-beans.xml something like this
       <bean name="EntityManagers" class="java.lang.Object">
       ...
       </bean>
      


      here is the persitent.xml and the test method in my EmbeddedEjb3TestCase.java
      
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence>
       <persistence-unit name="custdb">
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       </properties>
       </persistence-unit>
      </persistence>
      

       public void testEntityManager() throws Exception {
       EntityManager em = (EntityManager)getJBossSpecificInitialContext().lookup("java:/EntityManagers/custdb");
      
       TransactionManager tm = (TransactionManager)getJBossSpecificInitialContext().lookup("java:/TransactionManager");
      
       tm.begin();
      
       Customer cust = new Customer();
       cust.setName("Pouatcha");
       em.persist(cust);
      
       int id = cust.getId() ;
       assertTrue(cust.getId() > 0);
      
       println(cust.getName() + " wird in die DB mit einer Id " + id + " geschrieben");
      
       tm.commit();
      
       tm.begin();
       cust = em.find(Customer.class, id);
       assertNotNull(cust);
       tm.commit();
       }
      

      This Exception appears when the microcontainer try to bind EntityManagers
      EntityManager em = (EntityManager)getJBossSpecificInitialContext().lookup("java:/EntityManagers/custdb");
      


      If someone have a solution please post.

      Thank..