2 Replies Latest reply on Nov 6, 2003 12:34 PM by kpdcp

    CMR problem

    kpdcp Newbie

      I'm having a problem getting CMR field relationship set up in JBoss. I have two tables, student and attendance_reason. The attendance_reason table contains possible reasons a student might attend the class. The attendance_reason table has two columns, cd and desc (for code and description). What I want to happen is to have an attendance_reason_cd field in the student table that links to the cd field in the attendance_reason table.

      So it's a 1-to-many relationship, in that a student can have one attendance reason, but an attendance reason can belong to more than one student.

      I've been stuck on this for 2 WEEKS. Please help me if you can!!

      I get the following error when I try to deploy:
      CMP field for key not found: field name=CD]

      Here's how I have tried to set this up in the student bean. I'll be glad to post more code or XML, just let me know.

      /*
      * Created on Oct 14, 2003
      *
      * To change the template for this generated file go to
      * Window>Preferences>Java>Code Generation>Code and Comments
      */
      package com.paynetech.cmp;

      import javax.ejb.EntityBean;

      import com.paynetech.cmp.StudentUtil;

      /**
      * @ejb.bean name="Student"
      * jndi-name="StudentBean"
      * type="CMP"
      * primkey-field="ID"
      * schema="Student"
      * cmp-version="2.x"
      *
      * @ejb.persistence
      * table-name="STUDENT"
      *
      * @ejb.finder
      * query="SELECT OBJECT(a) FROM Student as a"
      * signature="java.util.Collection findAll()"
      *
      * @ejb.util generate="physical"
      *
      **/

      public abstract class StudentBean implements EntityBean {

      /**
      * The ejbCreate method.
      *
      * @ejb.create-method
      */
      public java.lang.String ejbCreate(
      String lastName,
      String firstName,
      String address,
      String city,
      String state,
      String zipCode,
      AttendanceReasonLocal attendanceReasonLocal)
      throws javax.ejb.CreateException {

      setID(StudentUtil.generateGUID(this));
      setLastName(lastName);
      setUpperLastName(lastName.toUpperCase());
      setAddress(address);
      setCity(city);
      setZipCode(zipCode);

      return null;
      }

      /**
      * The container invokes this method immediately after it calls ejbCreate.
      *
      */
      public void ejbPostCreate(
      String lastName,
      String firstName,
      String address,
      String city,
      String state,
      String zipCode,
      AttendanceReasonLocal attendanceReasonLocal)
      throws javax.ejb.CreateException {

      setAttendanceReason(attendanceReasonLocal);
      }

      /**
      * Returns the lastName
      * @return the lastName
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="LAST_NAME"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getLastName();

      /**
      * Sets the lastName
      *
      * @param java.lang.String the new lastName value
      *
      * @ejb.interface-method
      */
      public abstract void setLastName(java.lang.String lastName);

      /**
      * Returns the upperLastName
      * @return the upperLastName
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="UPPER_LAST_NAME"
      * sql-type="varchar"
      *
      */
      public abstract java.lang.String getUpperLastName();

      /**
      * Sets the upperLastName
      *
      * @param java.lang.String the new upperLastName value
      *
      */
      public abstract void setUpperLastName(java.lang.String lastName);

      /**
      * Returns the firstName
      * @return the firstName
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="FIRST_NAME"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getFirstName();

      /**
      * Sets the firstName
      *
      * @param java.lang.String the new firstName value
      *
      * @ejb.interface-method
      */
      public abstract void setFirstName(java.lang.String firstName);

      /**
      * Returns the address
      * @return the address
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="ADDRESS"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getAddress();

      /**
      * Sets the address
      *
      * @param java.lang.String the new address value
      *
      * @ejb.interface-method
      */
      public abstract void setAddress(java.lang.String address);

      /**
      * Returns the phoneNo
      * @return the phoneNo
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="PHONE_NO"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getPhoneNo();

      /**
      * Sets the phoneNo
      *
      * @param java.lang.String the new phoneNo value
      *
      * @ejb.interface-method
      */
      public abstract void setPhoneNo(java.lang.String phoneNo);

      /**
      * Returns the city
      * @return the city
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="CITY"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getCity();

      /**
      * Sets the city
      *
      * @param java.lang.String the new city value
      *
      * @ejb.interface-method
      */
      public abstract void setCity(java.lang.String city);

      /**
      * Returns the state
      * @return the state
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="STATE"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getState();

      /**
      * Sets the state
      *
      * @param java.lang.String the new state value
      *
      * @ejb.interface-method
      */
      public abstract void setState(java.lang.String state);

      /**
      * Returns the zipCode
      * @return the zipCode
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="ZIP_CODE"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getZipCode();

      /**
      * Sets the zipCode
      *
      * @param java.lang.String the new zipCode value
      *
      * @ejb.interface-method
      */
      public abstract void setZipCode(java.lang.String zipCode);

      /**
      * Returns the ID
      * @return the ID
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="ID"
      * sql-type="varchar"
      * @ejb.pk-field
      */
      public abstract java.lang.String getID();

      /**
      * Sets the ID
      *
      * @param java.lang.String the new ID value
      *
      */
      public abstract void setID(java.lang.String ID);

      /**
      * Returns the emailAddr
      * @return the emailAddr
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="EMAIL_ADDR"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getEmailAddr();

      /**
      * Sets the emailAddr
      *
      * @param java.lang.String the new emailAddr value
      *
      * @ejb.interface-method
      */
      public abstract void setEmailAddr(java.lang.String emailAddr);

      /**
      * Returns the birthDate
      * @return the birthDate
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="BIRTH_DATE"
      * sql-type="date"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getBirthDate();

      /**
      * Sets the emailAddr
      *
      * @param java.lang.String the new emailAddr value
      *
      * @ejb.interface-method
      */
      public abstract void setBirthDate(java.lang.String birthDate);

      /**
      * Returns the school
      * @return the school
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="SCHOOL"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */
      public abstract java.lang.String getSchool();

      /**
      * Sets the school
      *
      * @param java.lang.String the new school value
      *
      * @ejb.interface-method
      */
      public abstract void setSchool(java.lang.String school);

      /**
      * Returns the grade
      * @return the grade
      *
      * @ejb.persistent-field
      * @ejb.persistence
      * column-name="GRADE"
      * sql-type="varchar"
      *
      * @ejb.interface-method
      */

      public abstract java.lang.String getGrade();

      /**
      * Sets the grade
      *
      * @param java.lang.String the new grade value
      *
      * @ejb.interface-method
      */
      public abstract void setGrade(java.lang.String grade);

      /**
      * @return the #1 reason the student attends
      *
      * @ejb.interface-method
      *
      * @ejb.persistent-field
      *
      * @ejb.persistence
      * column-name="ATTENDANCE_REASON_CD"
      * sql-type="integer"
      *
      * @ejb.relation
      * name="Student-AttendanceReason"
      * role-name="Student-has-AttendanceReason"
      * target-ejb="AttendanceReason"
      * target-role-name="AttendanceReason-belongs-to-Student"
      * target-multiple="no"
      *
      * @jboss.target-relation
      * fk-constraint="true"
      * fk-column="ATTENDANCE_REASON_CD"
      * related-pk-field="CD"
      */
      public abstract AttendanceReasonLocal getAttendanceReason();

      /**
      * Sets the #1 reason the student attends
      *
      * @param AttendanceReasonLocal the new attendance reason
      *
      * @ejb.interface-method
      *
      */
      public abstract void setAttendanceReason(AttendanceReasonLocal attendanceReasonLocal);


      }



        • 1. Re: CMR problem
          Jacques Buitendag Newbie

          Hi,

          I had a simular problem.

          First your primary key field must start with a lower case letter.

          Second your related PK field should also start with a love case letter.

          The reason is that when you have getID and setID they are the set and get method for CMP field id. The same goes for the CMP field cd which is the primary key field of the other bean.

          Kind Regards
          Jacques Buitendag

          • 2. Re: CMR problem
            kpdcp Newbie

            I tried your suggestion, but still getting CMP field for key not found. Here's my latest bean code below. I'm really stumped on this, it seams like it ought to be easier to do.

            /*
            * Created on Oct 14, 2003
            *
            * To change the template for this generated file go to
            * Window>Preferences>Java>Code Generation>Code and Comments
            */
            package com.paynetech.cmp;

            import javax.ejb.EntityBean;

            import com.paynetech.cmp.StudentUtil;

            /**
            * @ejb.bean name="Student"
            * jndi-name="StudentBean"
            * type="CMP"
            * primkey-field="id"
            * schema="Student"
            * cmp-version="2.x"
            *
            * @ejb.persistence
            * table-name="STUDENT"
            *
            * @ejb.finder
            * query="SELECT OBJECT(a) FROM Student as a"
            * signature="java.util.Collection findAll()"
            *
            * @ejb.util generate="physical"
            *
            **/

            public abstract class StudentBean implements EntityBean {

            /**
            * The ejbCreate method.
            *
            * @ejb.create-method
            */
            public java.lang.String ejbCreate(
            String lastName,
            String firstName,
            String address,
            String city,
            String state,
            String zipCode,
            AttendanceReasonLocal attendanceReasonLocal)
            throws javax.ejb.CreateException {

            setId(StudentUtil.generateGUID(this));
            setLastName(lastName);
            setUpperLastName(lastName.toUpperCase());
            setAddress(address);
            setCity(city);
            setZipCode(zipCode);

            return null;
            }

            /**
            * The container invokes this method immediately after it calls ejbCreate.
            *
            */
            public void ejbPostCreate(
            String lastName,
            String firstName,
            String address,
            String city,
            String state,
            String zipCode,
            AttendanceReasonLocal attendanceReasonLocal)
            throws javax.ejb.CreateException {

            setAttendanceReason(attendanceReasonLocal);
            }

            /**
            * Returns the lastName
            * @return the lastName
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="LAST_NAME"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getLastName();

            /**
            * Sets the lastName
            *
            * @param java.lang.String the new lastName value
            *
            * @ejb.interface-method
            */
            public abstract void setLastName(java.lang.String lastName);

            /**
            * Returns the upperLastName
            * @return the upperLastName
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="UPPER_LAST_NAME"
            * sql-type="varchar"
            *
            */
            public abstract java.lang.String getUpperLastName();

            /**
            * Sets the upperLastName
            *
            * @param java.lang.String the new upperLastName value
            *
            */
            public abstract void setUpperLastName(java.lang.String lastName);

            /**
            * Returns the firstName
            * @return the firstName
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="FIRST_NAME"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getFirstName();

            /**
            * Sets the firstName
            *
            * @param java.lang.String the new firstName value
            *
            * @ejb.interface-method
            */
            public abstract void setFirstName(java.lang.String firstName);

            /**
            * Returns the address
            * @return the address
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="ADDRESS"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getAddress();

            /**
            * Sets the address
            *
            * @param java.lang.String the new address value
            *
            * @ejb.interface-method
            */
            public abstract void setAddress(java.lang.String address);

            /**
            * Returns the phoneNo
            * @return the phoneNo
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="PHONE_NO"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getPhoneNo();

            /**
            * Sets the phoneNo
            *
            * @param java.lang.String the new phoneNo value
            *
            * @ejb.interface-method
            */
            public abstract void setPhoneNo(java.lang.String phoneNo);

            /**
            * Returns the city
            * @return the city
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="CITY"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getCity();

            /**
            * Sets the city
            *
            * @param java.lang.String the new city value
            *
            * @ejb.interface-method
            */
            public abstract void setCity(java.lang.String city);

            /**
            * Returns the state
            * @return the state
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="STATE"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getState();

            /**
            * Sets the state
            *
            * @param java.lang.String the new state value
            *
            * @ejb.interface-method
            */
            public abstract void setState(java.lang.String state);

            /**
            * Returns the zipCode
            * @return the zipCode
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="ZIP_CODE"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getZipCode();

            /**
            * Sets the zipCode
            *
            * @param java.lang.String the new zipCode value
            *
            * @ejb.interface-method
            */
            public abstract void setZipCode(java.lang.String zipCode);

            /**
            * Returns the ID
            * @return the ID
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="id"
            * sql-type="varchar"
            * @ejb.pk-field
            */
            public abstract java.lang.String getId();

            /**
            * Sets the ID
            *
            * @param java.lang.String the new ID value
            *
            */
            public abstract void setId(java.lang.String id);

            /**
            * Returns the emailAddr
            * @return the emailAddr
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="EMAIL_ADDR"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getEmailAddr();

            /**
            * Sets the emailAddr
            *
            * @param java.lang.String the new emailAddr value
            *
            * @ejb.interface-method
            */
            public abstract void setEmailAddr(java.lang.String emailAddr);

            /**
            * Returns the birthDate
            * @return the birthDate
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="BIRTH_DATE"
            * sql-type="date"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getBirthDate();

            /**
            * Sets the emailAddr
            *
            * @param java.lang.String the new emailAddr value
            *
            * @ejb.interface-method
            */
            public abstract void setBirthDate(java.lang.String birthDate);

            /**
            * Returns the school
            * @return the school
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="SCHOOL"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */
            public abstract java.lang.String getSchool();

            /**
            * Sets the school
            *
            * @param java.lang.String the new school value
            *
            * @ejb.interface-method
            */
            public abstract void setSchool(java.lang.String school);

            /**
            * Returns the grade
            * @return the grade
            *
            * @ejb.persistent-field
            * @ejb.persistence
            * column-name="GRADE"
            * sql-type="varchar"
            *
            * @ejb.interface-method
            */

            public abstract java.lang.String getGrade();

            /**
            * Sets the grade
            *
            * @param java.lang.String the new grade value
            *
            * @ejb.interface-method
            */
            public abstract void setGrade(java.lang.String grade);

            /**
            * @return the #1 reason the student attends
            *
            * @ejb.interface-method
            *
            * @ejb.persistent-field
            *
            * @ejb.persistence
            * column-name="attendance_reason_cd"
            * sql-type="integer"
            *
            * @ejb.relation
            * name="Student-AttendanceReason"
            * role-name="Student-has-AttendanceReason"
            * target-ejb="AttendanceReason"
            * target-role-name="AttendanceReason-belongs-to-Student"
            * target-multiple="no"
            *
            * @jboss.target-relation
            * fk-constraint="true"
            * fk-column="attendance_reason_cd"
            * related-pk-field="cd"
            */
            public abstract AttendanceReasonLocal getAttendanceReason();

            /**
            * Sets the #1 reason the student attends
            *
            * @param AttendanceReasonLocal the new attendance reason
            *
            * @ejb.interface-method
            *
            */
            public abstract void setAttendanceReason(AttendanceReasonLocal attendanceReasonLocal);


            }