13 Replies Latest reply on Sep 9, 2002 5:42 PM by dsundstrom

    Why CMP is not deploying properly .........

    vickyk

      Hi,
      Can you guys explain me the steps which I have to do to make the CMP storing data in the Oracle DataBase?I have created the files but feel they assembly is going wrong.I am using jboss3.0.0 with embedded catalina.
      What I am trying to achieve is to create the Entity for the table with three fields having the first field as primary Key.Now this table has to present in the Oracle DB.This is the thing which I want to achieve,My files are as .................
      Roles.java
      ################
      package project.entity.roles;
      import java.rmi.RemoteException;
      import javax.ejb.*;

      public interface Roles extends EJBObject
      {
      public int getRoleId() throws RemoteException;

      public String getRoleName() throws RemoteException;

      public void setRoleName(String value) throws RemoteException;

      public String getRoleDescription() throws RemoteException;

      public void setRoleDescription(String value) throws RemoteException;

      }

      ################
      RolesHome.java
      ################
      package project.entity.roles;
      import java.util.Collection;
      import javax.ejb.*;
      import java.rmi.RemoteException;

      public interface RolesHome extends EJBHome
      {
      public Roles create(int id) throws CreateException, RemoteException;

      public Roles findByPrimaryKey(int key) throws RemoteException, FinderException;
      public Collection findAll() throws RemoteException, FinderException;
      }

      ################
      RolesEJB
      ################
      package project.entity.roles;
      import javax.ejb.*;

      public class RolesEJB implements EntityBean
      {
      protected EntityContext context;

      public int id;
      public String name;
      public String description;

      public int getRoleId()
      {
      return id;
      }

      public String getRoleName()
      {
      return name;
      }

      public void setRoleName(String value)
      {
      this.name = value;
      }

      public String getRoleDescription()
      {
      return description;
      }

      public void setRoleDescription(String value)
      {
      this.description = value;
      }

      public void ejbLoad()
      {
      }

      public void ejbStore()
      {
      }

      public void ejbActivate()
      {
      }

      public void ejbPassivate()
      {
      }

      public void ejbRemove()
      {
      }

      public void setEntityContext(EntityContext context)
      {
      this.context = context;
      }

      public void unsetEntityContext()
      {
      this.context = null;
      }

      public java.lang.Integer ejbCreate(int id) throws CreateException
      {
      this.id = id;
      return null; // Return null when using CMP
      }

      public void ejbPostCreate(int id)
      {
      }
      }

      ################
      ejb-jar.xml and jbosscmp-jdbc.xml
      ################
      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">
      <ejb-jar>


      <enterprise-beans>



      <ejb-name>Roles</ejb-name>
      project.entity.roles.RolesHome
      project.entity.roles.Roles
      <ejb-class>project.entity.roles.RolesEJB</ejb-class>
      <prim-key-class>java.lang.Integer</prim-key-class>
      True
      <persistence-type>Container</persistence-type>
      <cmp-field><field-name>id</field-name></cmp-field>
      <cmp-field><field-name>name</field-name></cmp-field>
      <cmp-field><field-name>description</field-name></cmp-field>
      <!-- If I dont place these fields I get error
      org.jboss.deployment.DeploymentException: Bean Roles has PK of type java.lang.In
      teger, so it should have a cmp-field named MIN_VALUE.I can't understand this
      -->
      <!-- cmp-field><field-name>MIN_VALUE</field-name></cmp-field>
      <cmp-field><field-name>MAX_VALUE</field-name></cmp-field>
      <cmp-field><field-name>TYPE</field-name></cmp-field -->
      <prim-key-field>id</prim-key-field>

      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>

      <ejb-name>Roles</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>
      _____________________________________________
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC
      "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
      "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
      <jbosscmp-jdbc>
      <enterprise-beans>

      <ejb-name>RolesEJB</ejb-name>
      <table-name>IT_SYSROLES</table-name>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>SRL_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>SRL_NAME</column-name>
      <not-null/>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>SRL_DESC</column-name>
      </cmp-field>

      </enterprise-beans>
      ################
      I require this very urgently..
      If possible please deploy on your system.....
      regards
      Vicky

        • 1. Re: Why CMP is not deploying properly .........
          dsundstrom

          So what is the problem? If you tell me, maybe I can help you.

          • 2. Re: Why CMP is not deploying properly .........
            vickyk

            Hi,
            You check the ejb-jar.xml it gives the problem and the server tells to define the MIN_VALUE,MAX_VALUE,TYPE....
            And after that it gets deployed with some warning and errors.What is the MIN_VALUE,MAX_VALUE and TYPE ......
            REFERENCE_________________________________________
            <!-- If I dont place these fields I get error
            org.jboss.deployment.DeploymentException: Bean Roles has PK of type java.lang.In
            teger, so it should have a cmp-field named MIN_VALUE.I can't understand this
            -->
            __________________________________________________
            Can you try of deploying this file and let me know the results.
            regards
            Vicky

            • 3. Re: Why CMP is not deploying properly .........
              dsundstrom

              In the future please describe the error at the top of the posting; I can't spot text like that in the middle of 2 pages of xml.

              The problem you are having is you have defined your primary key as a java.lang.Integer and the field as id, but id has type int. You need to change the type of id to Integer, the findByPrimaryKey method to take an Integer, and ejbCreate to return an Integer.

              • 4. Re: Why CMP is not deploying properly .........
                vickyk

                Hi,
                Where to change the id to Integer? Do u mean that in the the ejbCreate and findByPrimaryKey parameter need to be changed.I am telling the container regarding the primary key class in the ejb-jar.xml file.As per my understanding the Container will take care of generating the primary key class as an Integer and the finder to return the collection of Roles...It is a CMP....
                I have deployed the similar application in the orion,oc4j and weblogic how come it gets deployed there?
                thanks and regards
                Vicky

                • 5. Re: Why CMP is not deploying properly .........
                  vickyk

                  Hi,
                  Where to change the id to Integer? Do u mean that in the the ejbCreate and findByPrimaryKey parameter need to be changed.I am telling the container regarding the primary key class in the ejb-jar.xml file.As per my understanding the Container will take care of generating the primary key class as an Integer and the finder to return the collection of Roles...It is a CMP....
                  I have deployed the similar application in the orion,oc4j and weblogic how come it gets deployed there?
                  thanks and regards
                  Vicky

                  • 6. Re: Why CMP is not deploying properly .........
                    vickyk

                    Hi,
                    Where to change the id to Integer? Do u mean that in the the ejbCreate and findByPrimaryKey parameter need to be changed.I am telling the container regarding the primary key class in the ejb-jar.xml file.As per my understanding the Container will take care of generating the primary key class as an Integer and the finder to return the collection of Roles...It is a CMP....
                    I have deployed the similar application in the orion,oc4j and weblogic how come it gets deployed there?
                    thanks and regards
                    Vicky

                    • 7. Re: Why CMP is not deploying properly .........
                      vickyk

                      Hi,
                      My work is held from the longer time ,I would appericiate if you guys can share you experience in solving this one...
                      regards
                      Vicky

                      • 8. Re: Why CMP is not deploying properly .........
                        brecicure

                        CMP fields need to be java classes, not primitive types. Hence, you should make the appropiate changes in every place where a CMP field is being treated as a primitive type...

                        • 9. Re: Why CMP is not deploying properly .........
                          vickyk

                          Hi,
                          MIN_VALUE,MAX_VALUE and TYPE keeps troubling me I can understand what the container means.......
                          I am now fed up of making the changes of all sorts,can you guys demonostrate the deployment steps with some sample application.I am facing problembs with any other appservers.Please explain with the EJB1.1 specs......
                          regards
                          Vicky

                          • 10. Re: Why CMP is not deploying properly .........


                            What the previous reply to you meant was:

                            Your primary key has to be an Integer, not an int.

                            JBoss 3.0.0 is EJB 2.0 compliant, not EJB 1.1 compliant.

                            • 11. Re: Why CMP is not deploying properly .........
                              dsundstrom

                              > Where to change the id to Integer? Do u mean that
                              > at in the the ejbCreate and findByPrimaryKey
                              > parameter need to be changed.

                              Yes to all of the above plus you need to change the return type of the getter and the parameter type of the setter for the id field.

                              • 12. Re: Why CMP is not deploying properly .........
                                dsundstrom

                                > CMP fields need to be java classes, not primitive
                                > types. Hence, you should make the appropiate changes
                                > in every place where a CMP field is being treated as
                                > a primitive type...


                                No, only primary key field needs to be an object. You you use a compound primary key the individual fields may be primitives, but the primary key type is till an object.

                                Any non-primary-key field can be a primitive.

                                • 13. Re: Why CMP is not deploying properly .........
                                  dsundstrom

                                  > JBoss 3.0.0 is EJB 2.0 compliant, not EJB 1.1
                                  > compliant.


                                  We are backward compatiable also.