4 Replies Latest reply on Sep 26, 2012 10:35 AM by Dasari Prasad

    Entity bean(2.1)  not working in Jboss7.1.1

    Dasari Prasad Newbie

      I deployed using

      standalone -server-config=stanalone-full.xml

       

      normal entity bean with remote home remote interface

       

      public interface CMPHome extends EJBHome {

          public CMPRemote findByPrimaryKey(Integer id)throws FinderException,RemoteException;

          public CMPRemote create(int id,String name,String section,int qty,double cost)throws       RemoteException,CreateException;

            public List<CMPRemote> findStoreItems(String section)throws        FinderException,RemoteException;

      }

       

      public interface CMPRemote extends EJBObject {

          public void  setName(String name)throws RemoteException;   

          public void  setSection(String section)throws RemoteException;  

          public void  setQty(int qty)throws RemoteException;

          public void  setCost(double cst)throws RemoteException;

          public double getInventoryCost()throws RemoteException;

          public String getInfo()throws RemoteException;

      public abstract class CMPSimpleBean implements EntityBean {

          EntityContext etx;

        public abstract Integer getId();

        public abstract void  setId(Integer id);

        ---------------------------------

        other life-cycle methods

        public Integer ejbCreate(int id,

                                 String name,

                                 String section,

                                 int qty,

                                 double cost)

         throws CreateException {

          this.setId(new Integer(id));

          this.setName(name);

          this.setSection(section);

          this.setQty(qty);

          this.setCost(cost);

          return null;

        }

         

        public void ejbPostCreate(int id,

                                  String name,

                                  String section,

                                  int qty,

                                  double cost) {

        }   

         

        public double getInventoryCost() {

           return this.getCost()*this.getQty();

        }   

         

        public String getInfo() {

          StringBuffer sb = new StringBuffer();

          sb.append("Id:"+getId()+" Name:"+getName());

          sb.append(" Section:"+getSection()+" Qty:"+getQty());

          sb.append(" Cost:"+getCost());

          return sb.toString();

        }

      }

      ejb-jar.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar  xmlns="http://java.sun.com/xml/ns/j2ee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">

        <enterprise-beans>

         <entity>

         <ejb-name>STOREITEM</ejb-name>

         <home>com.htc.javaee.ejbs.CMPHome</home>

         <remote>com.htc.javaee.ejbs.CMPRemote</remote>

         <ejb-class>com.htc.javaee.ejbs.CMPSimpleBean</ejb-class>

         <persistence-type>Container</persistence-type>

         <prim-key-class>java.lang.Integer</prim-key-class>

         <reentrant>false</reentrant>

         <cmp-version>2.x</cmp-version>

         <abstract-schema-name>StoreItems</abstract-schema-name>

          <cmp-field><field-name>id</field-name></cmp-field>

          <cmp-field><field-name>name</field-name></cmp-field>

          <cmp-field><field-name>section</field-name></cmp-field>

          <cmp-field><field-name>qty</field-name></cmp-field>

          <cmp-field><field-name>cost</field-name></cmp-field>

          <primkey-field>id</primkey-field>

         <query>

          <query-method>

            <method-name>findStoreItems</method-name>

            <method-params>

             <method-param>java.lang.String</method-param>

            </method-params>

          </query-method>

          <ejb-ql>

           <![CDATA[select Object(it) from StoreItems as it

              where it.section=?1]]>   

          </ejb-ql>

         </query>

         </entity>

        </enterprise-beans>

      <assembly-descriptor>

      <container-transaction>

        <method>

          <ejb-name>STOREITEM</ejb-name>

          <method-name>*</method-name>

        </method>

        <trans-attribute>Required</trans-attribute>

      </container-transaction>

      </assembly-descriptor>

      </ejb-jar>

       

      jboss-cmp-jdbc.xml

       

      <?xml version='1.0' encoding='UTF-8' ?>

      <!DOCTYPE jbosscmp-jdbc PUBLIC

            "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"

            "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">

      <jbosscmp-jdbc >

          <defaults>

          <datasource>java:jboss/datasources/XAOracleDS</datasource>

          <datasource-mapping>Oracle9i</datasource-mapping>

          </defaults>

          <enterprise-beans>

           <entity>

             <ejb-name>STOREITEM</ejb-name>

             <table-name>STOREITEMS</table-name>

                  <cmp-field>

                   <field-name>id</field-name>

                   <column-name>STOREITEM_ID</column-name>

                  </cmp-field>

                

                  <cmp-field>

                    <field-name>name</field-name>

                    <column-name>STOREITEM_NAME</column-name>

              </cmp-field>

             

                  <cmp-field>

                    <field-name>section</field-name>

                    <column-name>STOREITEM_SECTION</column-name>

                  </cmp-field>

             

                  <cmp-field>

                   <field-name>qty</field-name>

                   <column-name>STOREITEM_QTY</column-name>

                  </cmp-field>

             

                  <cmp-field>

                   <field-name>cost</field-name>

                   <column-name>STOREITEM_COST_PIECE</column-name>

                   </cmp-field>   

                </entity>   

              </enterprise-beans>

      </jbosscmp-jdbc>

       

      jboss.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss> 

          <enterprise-beans>

              <entity>

              <ejb-name>STOREITEM</ejb-name>

              <jndi-name>Vivekananda</jndi-name>

              <configuration-name>Standard CMP 2.x EntityBean</configuration-name>

              </entity>

          </enterprise-beans>

      </jboss>

       

      my client is [uses jboss-ejb-client.properties & jndi.properties]

       

      public class SimpCMPClient {

       

          public static InitialContext getInitialContext()  {

            Properties props = new Properties();

            InitialContext jndiCtx = null;

            try {

              props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

              props.put("jboss.naming.client.ejb.context", true);

              jndiCtx = new InitialContext(props); 

            }catch(Exception ex) {}

             return jndiCtx;

          }

          public static final String DEPLOY_NAME =

               "ejb:/simpCMP//STOREITEM!com.htc.javaee.ejbs.CMPHome";

             

             public static void main(String[] args) {

              System.out.println("\nBegin SimpCMPClient...\n");

          try  {

               InitialContext ctx = getInitialContext();

       

               Object obj = ctx.lookup(DEPLOY_NAME); 

               System.out.println("****"+obj);

           CMPHome home =

                  (CMPHome)PortableRemoteObject.narrow(obj,

                                             CMPHome.class);

               System.out.println("****"+home);

          

               System.out.println("Creating SimpCMPBean\n");

              

               CMPRemote demo = home.create(500, "Brake Drum", "I", 20, 4500.6);

               System.out.println("Created bean is:" + demo.getInfo() + "\n");

               System.out.println("Finder Method");

       

               demo = home.findByPrimaryKey(300);

               System.out.println(demo.getInfo() + "\n");

               demo.setQty(60); 

               System.out.println("Setter Method");

               System.out.println(demo.getInfo() + "\n");

       

               System.out.println("Multi Finder Method");

               List<CMPRemote> list = home.findStoreItems("II");

               System.out.println();  

             

               for(CMPRemote remote : list) {

                System.out.println(remote.getInfo());        

               }

          }catch(Exception e){

              e.printStackTrace();       

          }

         }

         

      }

      when i run , i am  getting

      java]

           [java] Begin SimpCMPClient...

           [java]

           [java] 2012-09-23 09:44:34,482 INFO  org.jboss.ejb.client.<clinit>:42 - JBoss EJB Client version 1.0.5.Final

           [java] ****Proxy for remote EJB EJBHomeLocator{appName='', moduleName='simpCMP', distinctName='', beanName='STOREITEM', view='interface com.htc.javaee.ejbs.CMPHome'}

           [java] ****Proxy for remote EJB EJBHomeLocator{appName='', moduleName='simpCMP', distinctName='', beanName='STOREITEM', view='interface com.htc.javaee.ejbs.CMPHome'}

           [java] Creating SimpCMPBean

           [java]

           [java] java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:simpCMP,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@23a0d3

           [java]     at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)

           [java]     at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)

           [java]     at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)

           [java]     at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)

           [java]     at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

           [java]     at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

           [java]     at $Proxy0.create(Unknown Source)

           [java]     at com.htc.javaee.ejbs.SimpCMPClient.main(Unknown Source)

           [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

           [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

           [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

           [java]     at java.lang.reflect.Method.invoke(Method.java:601)

           [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)

           [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)

           [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)

           [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)

           [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)

           [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)

           [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

           [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

           [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

           [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

           [java]     at java.lang.reflect.Method.invoke(Method.java:601)

           [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

           [java]     at org.apache.tools.ant.Task.perform(Task.java:348)

           [java]     at org.apache.tools.ant.Target.execute(Target.java:390)

           [java]     at org.apache.tools.ant.Target.performTasks(Target.java:411)

           [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)

           [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)

           [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)

           [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)

           [java]     at org.apache.tools.ant.Main.runBuild(Main.java:809)

           [java]     at org.apache.tools.ant.Main.startAnt(Main.java:217)

           [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)

           [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

       

      BUILD SUCCESSFUL

       

      can any one look into this and provide solution