1 Reply Latest reply on Aug 7, 2007 12:00 AM by Sudhakar Ramasamy

    Maven + Embedded EJB + JPA +EJB 3.0 getting Null name

    Sudhakar Ramasamy Newbie

      Hrere is the code that starts up the embedded JBoss micro-container.

      public void beforeIntegrationTests() {
       try {
      
       // Boot the JBoss Microcontainer with EJB3 settings, loads
       // ejb3-interceptors-aop.xml
       EJB3StandaloneBootstrap.boot(null);
      
       // EJB3StandaloneBootstrap.deployXmlResource("jboss-jms-beans.xml");
       // scan classpath for ejbs and MDBs
       EJB3StandaloneBootstrap.scanClasspath();
      
       // Add all EJBs found in the archive that has this file
       deployer = new EJB3StandaloneDeployer();
       deployer.getArchivesByResource().add("META-INF/persistence.xml");
      
       // Deploy everything we got
       deployer.create();
       deployer.start();
      
       // Create InitialContext from jndi.properties
       initialContext = new InitialContext();
      
       } catch (Exception ex) {
       throw new RuntimeException(ex);
       }
       }


      I am getting the following stacktrace at

      EJB3StandaloneBootstrap.scanClasspath();



      java.lang.RuntimeException: java.lang.IllegalArgumentException: Null name
      at brazos.permit.ejb.container.EJB3Container.beforeIntegrationTests(EJB3Container.java:52)
      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:597)
      at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:604)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:470)
      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:564)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:830)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
      at org.testng.TestRunner.runWorkers(TestRunner.java:678)
      at org.testng.TestRunner.privateRun(TestRunner.java:624)
      at org.testng.TestRunner.run(TestRunner.java:495)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
      at org.testng.SuiteRunner.run(SuiteRunner.java:190)
      at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
      at org.testng.TestNG.run(TestNG.java:699)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
      Caused by: java.lang.IllegalArgumentException: Null name
      at org.jboss.dependency.plugins.AbstractController.getContext(AbstractController.java:114)
      at org.jboss.kernel.plugins.dependency.AbstractKernelController.getContext(AbstractKernelController.java:94)
      at org.jboss.ejb3.embedded.KernelErrors.validate(KernelErrors.java:96)
      at org.jboss.ejb3.embedded.EJB3StandaloneBootstrap.scanClasspath(EJB3StandaloneBootstrap.java:281)
      at brazos.permit.ejb.container.EJB3Container.beforeIntegrationTests(EJB3Container.java:38)
      ... 22 more



      Here is my persistence.xml

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       version="1.0">
       <persistence-unit name="myPU">
       <jta-data-source>jdbc/MyDB</jta-data-source>
       <properties>
       <property name="toplink.ddl-generation"
       value="create-tables" />
       <property name="toplink.logging.level"
       value="FINER" />
       </properties>
       </persistence-unit>
      </persistence>


      I'm using maven and my folder structure is as follows:

      srv/main/java
      |__________META-INF
      |________persistence.xml
      src/test/java
      |__________EJB2Container.java


      Please let me know if there is anything else I can provide to help get this working.

      Thanks!

        • 1. Re: Maven + Embedded EJB + JPA +EJB 3.0 getting Null name
          Sudhakar Ramasamy Newbie

          Took me a while to get this but here it is:

          The persistence.xml should look almost exactly like below:

          <persistence>
           <persistence-unit name="myPU">
           <jta-data-source>java:/MyDB</jta-data-source>
           <properties>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
           <property name="hibernate.hbm2ddl.auto" value="update" />
           </properties>
           </persistence-unit>
          </persistence>


          Each tag should be in one single line with no line breaks. The Null name I was getting is most likely a bug in parsing this persistence.xml file with line breaks.

          Also, since I was coming from a toplink background I found that the data source has to be name "java:/MyDB" as opposed to "jdbc/MyDB"

          Then make sure you have the corresponding data source defined in embedded-jboss-beans.xml as below

          <bean name="MyDB" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
           <property name="driverClass">com.mysql.jdbc.Driver</property>
           <property name="connectionURL">jdbc:mysql://dev1:3306/mydb?user=root&password=hello</property>
           <property name="jndiName">java:/MyDB</property>
           <property name="transactionManager"><inject bean="TransactionManager"/></property>
           <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
           <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
           </bean>
          



          Finally here is a method that will test your code:
          public void create() throws Exception {
           Owner owner = new Owner();
           OwnerData ownerData = new OwnerData();
           ownerData.setName("Test Company");
           ownerData.setContact("Richard");
           ownerData.setPhone("979-777-7777");
           owner.setOwnerData(ownerData);
          
           EJB3StandaloneBootstrap.boot(null);
           EJB3StandaloneBootstrap.scanClasspath();
          
           InitialContext ctx = getInitialContext();
          
           OwnerDAO dao = (OwnerDAO) ctx.lookup("OwnerDAOBean/local");
           dao.create(owner);
           EJB3StandaloneBootstrap.shutdown();
           }


          I was having problems trying to get the lookup to work when the container was being started by a BeforeGroups method. But I've save that for another post. Once you get it all working it's pretty cool :)