2 Replies Latest reply on Jul 30, 2008 7:36 AM by zhuhuapeng

    Accessing stateless EJB3 bean from a ejb-jar

    zhuhuapeng

      this problem had been nagging me for days,i had made a project using ejb3. and deployed it to jboss4.2.3GA. the following is part of my project:

      1:persistence.xml

      <persistence-unit name="cattle_persis"
      transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/cattleDB</jta-data-source>
      <properties>
      <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory" />
      <property name="org.hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>

      2:interface
      @Remote
      public interface ICustomerService {
      public void persist(CustomerEO eo);
      }

      3:bean
      @Stateless
      public class CustomerService implements ICustomerService {
      @PersistenceContext(unitName="cattle_persis")
      private EntityManager entityManager;
      public void persist(CustomerEO eo) {
       entityManager.persist(eo);
      }
      }
      

      4:entity
      @Entity
      @Table(name="CUSTOMER")
      public class CustomerEO {...
      

      5:testClient
      ...
      Hashtable<String,String> props = new Hashtable<String,String>();
      props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      props.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
      context = new InitialContext(props);
      ...
      Context ctx = getInitialContext();
      Object obj = ctx.lookup("CustomerService/remote");
      ICustomerService service = (ICustomerService)PortableRemoteObject.narrow(obj,
       ICustomerService.class);
      ....
      


      then run jboss, part of the loginfo
      [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=/cattleDB' to JNDI name 'java:/cattleDB'
      17:01:19,664 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
      17:01:19,667 INFO [JmxKernelAbstraction] installing MBean: persistence.units:jar=demoEJB-1.0.jar,unitName=cattle_persis with dependencies:
      17:01:19,667 INFO [JmxKernelAbstraction] jboss.jca:name=cattleDB,service=DataSourceBinding
      17:01:19,853 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
      17:01:19,857 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=demoEJB-1.0.jar,name=CustomerService,service=EJB3 with dependencies:
      17:01:19,857 INFO [JmxKernelAbstraction] persistence.units:jar=demoEJB-1.0.jar,unitName=cattle_persis
      17:01:19,859 INFO [EJB3Deployer] Deployed: file:/E:/TheOrc/base/jboss-4.2.3.GA/server/default/deploy/demoEJB-1.0.jar
      17:01:19,886 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
      17:01:20,009 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
      
      --- MBeans waiting for other MBeans ---
      ObjectName: persistence.units:jar=demoEJB-1.0.jar,unitName=cattle_persis
       State: NOTYETINSTALLED
       I Depend On:
       jboss.jca:name=cattleDB,service=DataSourceBinding
       Depends On Me:
       jboss.j2ee:jar=demoEJB-1.0.jar,name=CustomerService,service=EJB3
      
      ObjectName: jboss.j2ee:jar=demoEJB-1.0.jar,name=CustomerService,service=EJB3
       State: NOTYETINSTALLED
       I Depend On:
       persistence.units:jar=demoEJB-1.0.jar,unitName=cattle_persis
      
      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: jboss.jca:name=cattleDB,service=DataSourceBinding
       State: NOTYETINSTALLED
       Depends On Me:
       persistence.units:jar=demoEJB-1.0.jar,unitName=cattle_persis
      


      in jmx-console page,get the following message:
      persistence.units
      jar=demoEJB-1.0.jar,unitName=cattle_persis
      


      at last ,run testClient,and got the following exception:
      Exception in thread "main" javax.naming.NameNotFoundException: CustomerService not bound
      ...
      


      can there anyone help me to resolve this problem,very thanks.

        • 1. Re: Accessing stateless EJB3 bean from a ejb-jar
          jaikiran

           

          ObjectName: jboss.jca:name=cattleDB,service=DataSourceBinding
          State: NOTYETINSTALLED
          Depends On Me:
          persistence.units:jar=demoEJB-1.0.jar,unitName=cattle_persis


          This shows that the datasource is not yet bound. But earlier in the log:

          [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=/cattleDB' to JNDI name 'java:/cattleDB'


          This indicates that the datasource is being bound. The only strange thing that i see in that log message is the front-slash in:

          'jboss.jca:service=DataSourceBinding,name=/cattleDB'


          Can you post the contents of your datasource file (*-ds.xml) and where is it placed?




          • 2. Re: Accessing stateless EJB3 bean from a ejb-jar
            zhuhuapeng

            You said the problem was absolutely correct
            the previous configuration of oracle-ds.xml looks like this:

            <datasources>
             <local-tx-datasource>
             <jndi-name>/cattleDB</jndi-name>
             ....
            

            and now i have modified it as the following
            <datasources>
             <local-tx-datasource>
             <jndi-name>cattleDB</jndi-name>
             ....
            

            then run,everything is ok .
            thanks for your help !!