8 Replies Latest reply on Mar 30, 2002 1:56 PM by mulicheng

    CMP 2.0 in JBoss 3.0

    jrank

      I'm trying to deploy an entity bean with CMP 2.0 in JBoss 3.0.0alpha (which I downloaded this week). The following warnings show up when I deploy:

      [10:54:34,563,ContainerFactory]
      Bean : OrderEJB
      Section: 9.2.2
      Warning: The entity bean class must not be defined as abstract.

      [10:54:34,565,ContainerFactory]
      Bean : OrderEJB
      Section: 9.2.2
      Warning: The entity bean class must define a public constructor that takes no arguments.

      [10:54:34,568,ContainerFactory]
      Bean : OrderEJB
      Section: 9.4.7.1
      Warning: The primkey-field element must name a public field in the bean implementation class.

      (I saw the other post on this, but I am using JBoss 3.0.) The bean deploys, but when I try to access it with a session bean, I get an InstantiationException:

      [11:05:31,866,LogInterceptor] TransactionRolledbackException, causedBy:
      java.rmi.ServerException: Could not instantiate bean; nested exception is:
      java.lang.InstantiationException: net.trapdoor.webom.order.OrderBean
      java.lang.InstantiationException: net.trapdoor.webom.order.OrderBean
      at java.lang.Class.newInstance0(Native Method)
      at java.lang.Class.newInstance(Class.java:237)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createBeanClassInstance(CMPPersistenceManager.java:155)
      at org.jboss.ejb.EntityContainer.createBeanClassInstance(EntityContainer.java:276)
      at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.java:153)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:142)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:104)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:100)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:56)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:106)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:441)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(BaseLocalContainerInvoker.java:255)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$HomeProxy.invoke(BaseLocalContainerInvoker.java:406)
      at $Proxy27.create(Unknown Source)
      at net.trapdoor.webom.WorkflowManagerBean.createOrder(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:569)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:67)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:65)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:131)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:280)
      at org.jboss.ejb.Container.invoke(Container.java:528)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:411)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      at sun.rmi.transport.Transport$1.run(Transport.java:152)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
      at java.lang.Thread.run(Thread.java:484)

      The classes couldn't be much simpler:

      <CODE>
      ------------- Home ------------------
      package mypkg.order;

      import javax.ejb.*;

      public interface LocalOrderHome extends EJBLocalHome {
      public LocalOrder create(Integer oid) throws CreateException;
      public LocalOrder findByPrimaryKey(Integer key) throws FinderException;
      }

      ------------- Local ----------------package mypkg.order;

      import javax.ejb.*;

      public interface LocalOrder extends EJBLocalObject {
      public Integer getOrderId();
      }

      -------------- Bean ----------------
      package mypkg.order;
      import javax.ejb.*;

      public abstract class OrderBean implements EntityBean {
      private EntityContext context;

      public abstract Integer getOrderId();
      public abstract void setOrderId(Integer oid);

      public Integer ejbCreate(Integer oid) throws CreateException {
      setOrderId(oid);
      return null;
      }

      publid void ejbPostCreate(Integer oid) throws CreateException { }

      public void setEntityContext(EntityContext ec) {
      context = ec;
      }
      public void unsetEntityContext() {
      context = null;
      }

      public void ejbActivate() { }
      public void ejbPassivate() { }
      public void ejbLoad() { }
      public void ejbRemove() { }
      public void ejbStore() { }
      }
      </CODE>

      The deployment descriptor is as EJB 2.0 as I know how to make it:

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

      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise Java Beans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

      <ejb-jar>
      <display-name>OrderJAR</display-name>
      <enterprise-beans>
      <entity>
      <display-name>OrderEJB</display-name>
      <ejb-name>OrderEJB</ejb-name>
      <local-home>mypkg.order.LocalOrderHome</local-home>
      <local>mypkg.order.LocalOrder</local>
      <ejb-class>mypkg.order.OrderBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      <reentrant>True</reentrant>
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>orderSchema</abstract-schema-name>
      <cmp-field>
      <field-name>orderId</field-name>
      </cmp-field>
      <primkey-field>orderId</primkey-field>
      <security-identity>
      <description></description>
      <use-caller-identity></use-caller-identity>
      </security-identity>
      </entity>
      </enterprise-beans>
      <assembly-descriptor>
      <method-permission>
      <unchecked />
      <method>
      <ejb-name>OrderEJB</ejb-name>
      <method-name>*</method-name>
      </method>
      </method-permission>
      <container-transaction>
      <method>
      <ejb-name>OrderEJB</ejb-name>
      <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>


      Any help will score you some major karma, to be sure.

      -Joe

        • 1. Re: CMP 2.0 in JBoss 3.0
          ppetit

          I think you forgot to use the ejb2.0 DTD header in your ejb-jar.xml file.
          check this !

          • 2. Re: CMP 2.0 in JBoss 3.0
            kevina

            to ppedit:

            What is missing to make the ejb-jar.xml 2.0 compliant? I don't see what you're saying. I'm of the opinion that somehow JBOSS is thinking it's a non-2.0 bean but where I can't figure out.

            -kevin

            • 3. Re: CMP 2.0 in JBoss 3.0
              jrank

              The following DOCTYPE tag (included in the original post) is at the top of the ejb-jar.xml file:

              <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise Java Beans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

              Is something other than this needed?

              • 4. Re: CMP 2.0 in JBoss 3.0
                jrank

                The painful yet welcome solution is the superfluous space in the DOCTYPE PUBLIC identifier:

                ...//DTD Enterprise Java Beans 2.0//...

                should be

                ...//DTD Enterprise JavaBeans 2.0//...

                [no space b/w "Java" and "Beans"]

                I hope someone recovers some time by this post. Thanks for the help, Phillipe.

                JBoss ROCKS!!

                • 5. Re: CMP 2.0 in JBoss 3.0
                  zerosleep

                  I have mine set to:

                  <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

                  and i STILL get JBOSS 3.0 giving me errors about entity beans being declared as abstract. I also have CMP-VERSION set to 2.x, but nothing works.

                  Are there other reasons jboss 3 alpha would generate this error?

                  • 6. Re: CMP 2.0 in JBoss 3.0
                    zerosleep

                    I guess my DTD was STILL wrong. I had to change it to:

                    <?xml version="1.0"?>

                    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">

                    • 7. Re: CMP 2.0 in JBoss 3.0
                      mulicheng

                      I have the exact problem with CMP 2.0 on 3.0 beta 2 from CVS.

                      I've tried modifying the header to match what is listed here and the same thing happens.

                      By the Way -- the url is: http://java.sun.com/dtd/ejb-jar_2_0.dtd --- not http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd <-- NOTE the /j2ee/dtds/ is an old url

                      Anyway, I get those same warnings about my Bean should not be declared abstract, etc..

                      Anyone have any suggestions?

                      • 8. Re: CMP 2.0 in JBoss 3.0
                        mulicheng

                        The sourcecode to jboss has revealed the answer to this question. The important part of the DTD is not just the

                        Enterprise JavaBeans 2.0...

                        it's also the part about Sun Microsystems, Inc.

                        The <!DOCTYPE tag must read exactly letter for letter and case sensitive according the the DTD. JBoss checks to see if the doctype is the same as the DTD, but there is no forgiveness if even one character is different. If you don't have EXACTLY the 2.0 DOCTYPE, JBoss defaults back to 1.x.

                        My problem was that there was no "." after "Inc"
                        ie: Sun Microsystems, Inc// instead of Sun Microsystems, Inc.//

                        One of the examples above had a lower case i for inc.

                        Hope this helps.