2 Replies Latest reply on Sep 6, 2005 11:24 AM by Martin Ganserer

    Problems with Many to One Relationship

    Steve Rose Newbie

      I have 3 tables APPROLE, APPFUNCTION and APPROLEFUNCTION. APPROLE and APPFUNCTION have foreign keys in APPROLEFUNCTION. I want to pass a String Value(APPROLE name or APPFUNCTION name ) into my APPROLEFUNCTION entity bean and have it create a new record. This is what I Currently Have:

      /**
      * The AppRoleFunction entity bean.
      *
      * @author Rudie Ekkelenkamp - Finalist IT Group
      * @version $Revision: 1.11 $, $Date: 2005/03/23 18:52:25 $
      */

      @Table(name = "APPROLEFUNCTION")

      @Entity
      @IdClass(com.demo.AppRoleFunctionPK.class)
      public class AppRoleFunction {

      /**
      * The logger object.
      */


      private AppRole arfRoleNameAppRole;
      private AppFunction arfFunctionNameAppFunction;




      private java.sql.Date arfCreatedWhen;
      private java.lang.String arfCreatedBy;
      private java.sql.Date arfChangedWhen;
      private java.lang.String arfChangedBy;

      /**
      * Default constructor.
      */
      public AppRoleFunction() {
      }

      /**
      * Value object constructor.
      */
      public AppRoleFunction(com.demo.AppRoleFunctionObj value) {
      setArfRoleName(value.getArfRoleName());
      setArfFunctionName(value.getArfFunctionName());
      setArfCreatedWhen(value.getArfCreatedWhen());
      setArfCreatedBy(value.getArfCreatedBy());
      setArfChangedWhen(value.getArfChangedWhen());
      setArfChangedBy(value.getArfChangedBy());
      }







      /**
      * Returns the value of the arfCreatedWhen property.
      *
      */
      @Column(name = "ARF_CREATED_WHEN")
      public java.sql.Date getArfCreatedWhen() {
      return arfCreatedWhen;
      }

      /**
      * Sets the value of the arfCreatedWhen property.
      *
      * @param arfCreatedWhen the value for the arfCreatedWhen property
      */
      public void setArfCreatedWhen(java.sql.Date arfCreatedWhen) {
      this.arfCreatedWhen = arfCreatedWhen;
      }

      /**
      * Returns the value of the arfCreatedBy property.
      *
      */
      @Column(name = "ARF_CREATED_BY")
      public java.lang.String getArfCreatedBy() {
      return arfCreatedBy;
      }

      /**
      * Sets the value of the arfCreatedBy property.
      *
      * @param arfCreatedBy the value for the arfCreatedBy property
      */
      public void setArfCreatedBy(java.lang.String arfCreatedBy) {
      this.arfCreatedBy = arfCreatedBy;
      }

      /**
      * Returns the value of the arfChangedWhen property.
      *
      */
      @Column(name = "ARF_CHANGED_WHEN")
      public java.sql.Date getArfChangedWhen() {
      return arfChangedWhen;
      }

      /**
      * Sets the value of the arfChangedWhen property.
      *
      * @param arfChangedWhen the value for the arfChangedWhen property
      */
      public void setArfChangedWhen(java.sql.Date arfChangedWhen) {
      this.arfChangedWhen = arfChangedWhen;
      }

      /**
      * Returns the value of the arfChangedBy property.
      *
      */
      @Column(name = "ARF_CHANGED_BY")
      public java.lang.String getArfChangedBy() {
      return arfChangedBy;
      }

      /**
      * Sets the value of the arfChangedBy property.
      *
      * @param arfChangedBy the value for the arfChangedBy property
      */
      public void setArfChangedBy(java.lang.String arfChangedBy) {
      this.arfChangedBy = arfChangedBy;
      }

      @ManyToOne
      @JoinColumn(name = "ARF_ROLE_NAME")
      public AppRole getArfRoleNameAppRole() {
      return this.arfRoleNameAppRole;
      }

      public void setArfRoleNameAppRole(AppRole approle) {
      this.arfRoleNameAppRole=approle;
      }

      @Transient
      public void setArfRoleName(java.lang.String arRoleName){
      arfRoleNameAppRole.setArRoleName(arRoleName);
      }

      @Transient
      public java.lang.String getArfRoleName() {
      return arfRoleNameAppRole.getArRoleName();
      }

      @ManyToOne
      @JoinColumn(name = "ARF_FUNCTION_NAME")
      public AppFunction getArfFunctionNameAppFunction() {
      return this.arfFunctionNameAppFunction;
      }

      public void setArfFunctionNameAppFunction(AppFunction appfunction) {
      this.arfFunctionNameAppFunction=appfunction;
      }

      @Transient
      public void setArfFunctionName(java.lang.String afFunctionName){
      arfFunctionNameAppFunction.setAfFunctionName(afFunctionName);
      }

      @Transient
      public java.lang.String getArfFunctionName() {
      return arfFunctionNameAppFunction.getAfFunctionName();
      }


      }

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

      /**
      * The AppFunction entity bean.
      *
      * @author Rudie Ekkelenkamp - Finalist IT Group
      * @version $Revision: 1.11 $, $Date: 2005/03/23 18:52:25 $
      */

      @Table(name = "APPFUNCTION")

      @Entity
      public class AppFunction {

      /**
      * The logger object.
      */






      private java.lang.String afFunctionName;
      private java.lang.String afFunctionDesc;
      private java.lang.String afAppComponent;
      private java.lang.String afQueryInd;
      private java.lang.String afCreateInd;
      private java.lang.String afDeleteInd;
      private java.lang.String afUpdateInd;
      private java.sql.Date afCreatedWhen;
      private java.lang.String afCreatedBy;
      private java.sql.Date afChangedWhen;
      private java.lang.String afChangedBy;

      /**
      * Default constructor.
      */
      public AppFunction() {
      }

      /**
      * Value object constructor.
      */
      public AppFunction(com.demo.AppFunctionObj value) {
      setAfFunctionName(value.getAfFunctionName());
      setAfFunctionDesc(value.getAfFunctionDesc());
      setAfAppComponent(value.getAfAppComponent());
      setAfQueryInd(value.getAfQueryInd());
      setAfCreateInd(value.getAfCreateInd());
      setAfDeleteInd(value.getAfDeleteInd());
      setAfUpdateInd(value.getAfUpdateInd());
      setAfCreatedWhen(value.getAfCreatedWhen());
      setAfCreatedBy(value.getAfCreatedBy());
      setAfChangedWhen(value.getAfChangedWhen());
      setAfChangedBy(value.getAfChangedBy());
      }




      /**
      * Returns the value of the afFunctionName property.
      *
      */
      @Column(name = "AF_FUNCTION_NAME")
      @Id(generate = GeneratorType.NONE)
      public java.lang.String getAfFunctionName() {
      return afFunctionName;
      }

      /**
      * Sets the value of the afFunctionName property.
      *
      * @param afFunctionName the value for the afFunctionName property
      */
      public void setAfFunctionName(java.lang.String afFunctionName) {
      this.afFunctionName = afFunctionName;
      }

      /**
      * Returns the value of the afFunctionDesc property.
      *
      */
      @Column(name = "AF_FUNCTION_DESC")
      public java.lang.String getAfFunctionDesc() {
      return afFunctionDesc;
      }

      /**
      * Sets the value of the afFunctionDesc property.
      *
      * @param afFunctionDesc the value for the afFunctionDesc property
      */
      public void setAfFunctionDesc(java.lang.String afFunctionDesc) {
      this.afFunctionDesc = afFunctionDesc;
      }

      /**
      * Returns the value of the afAppComponent property.
      *
      */
      @Column(name = "AF_APP_COMPONENT")
      public java.lang.String getAfAppComponent() {
      return afAppComponent;
      }

      /**
      * Sets the value of the afAppComponent property.
      *
      * @param afAppComponent the value for the afAppComponent property
      */
      public void setAfAppComponent(java.lang.String afAppComponent) {
      this.afAppComponent = afAppComponent;
      }

      /**
      * Returns the value of the afQueryInd property.
      *
      */
      @Column(name = "AF_QUERY_IND")
      public java.lang.String getAfQueryInd() {
      return afQueryInd;
      }

      /**
      * Sets the value of the afQueryInd property.
      *
      * @param afQueryInd the value for the afQueryInd property
      */
      public void setAfQueryInd(java.lang.String afQueryInd) {
      this.afQueryInd = afQueryInd;
      }

      /**
      * Returns the value of the afCreateInd property.
      *
      */
      @Column(name = "AF_CREATE_IND")
      public java.lang.String getAfCreateInd() {
      return afCreateInd;
      }

      /**
      * Sets the value of the afCreateInd property.
      *
      * @param afCreateInd the value for the afCreateInd property
      */
      public void setAfCreateInd(java.lang.String afCreateInd) {
      this.afCreateInd = afCreateInd;
      }

      /**
      * Returns the value of the afDeleteInd property.
      *
      */
      @Column(name = "AF_DELETE_IND")
      public java.lang.String getAfDeleteInd() {
      return afDeleteInd;
      }

      /**
      * Sets the value of the afDeleteInd property.
      *
      * @param afDeleteInd the value for the afDeleteInd property
      */
      public void setAfDeleteInd(java.lang.String afDeleteInd) {
      this.afDeleteInd = afDeleteInd;
      }

      /**
      * Returns the value of the afUpdateInd property.
      *
      */
      @Column(name = "AF_UPDATE_IND")
      public java.lang.String getAfUpdateInd() {
      return afUpdateInd;
      }

      /**
      * Sets the value of the afUpdateInd property.
      *
      * @param afUpdateInd the value for the afUpdateInd property
      */
      public void setAfUpdateInd(java.lang.String afUpdateInd) {
      this.afUpdateInd = afUpdateInd;
      }

      /**
      * Returns the value of the afCreatedWhen property.
      *
      */
      @Column(name = "AF_CREATED_WHEN")
      public java.sql.Date getAfCreatedWhen() {
      return afCreatedWhen;
      }

      /**
      * Sets the value of the afCreatedWhen property.
      *
      * @param afCreatedWhen the value for the afCreatedWhen property
      */
      public void setAfCreatedWhen(java.sql.Date afCreatedWhen) {
      this.afCreatedWhen = afCreatedWhen;
      }

      /**
      * Returns the value of the afCreatedBy property.
      *
      */
      @Column(name = "AF_CREATED_BY")
      public java.lang.String getAfCreatedBy() {
      return afCreatedBy;
      }

      /**
      * Sets the value of the afCreatedBy property.
      *
      * @param afCreatedBy the value for the afCreatedBy property
      */
      public void setAfCreatedBy(java.lang.String afCreatedBy) {
      this.afCreatedBy = afCreatedBy;
      }

      /**
      * Returns the value of the afChangedWhen property.
      *
      */
      @Column(name = "AF_CHANGED_WHEN")
      public java.sql.Date getAfChangedWhen() {
      return afChangedWhen;
      }

      /**
      * Sets the value of the afChangedWhen property.
      *
      * @param afChangedWhen the value for the afChangedWhen property
      */
      public void setAfChangedWhen(java.sql.Date afChangedWhen) {
      this.afChangedWhen = afChangedWhen;
      }

      /**
      * Returns the value of the afChangedBy property.
      *
      */
      @Column(name = "AF_CHANGED_BY")
      public java.lang.String getAfChangedBy() {
      return afChangedBy;
      }

      /**
      * Sets the value of the afChangedBy property.
      *
      * @param afChangedBy the value for the afChangedBy property
      */
      public void setAfChangedBy(java.lang.String afChangedBy) {
      this.afChangedBy = afChangedBy;
      }


      }

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

      /**
      * The AppRole entity bean.
      *
      * @author Rudie Ekkelenkamp - Finalist IT Group
      * @version $Revision: 1.11 $, $Date: 2005/03/23 18:52:25 $
      */

      @Table(name = "APPROLE")

      @Entity
      public class AppRole {

      /**
      * The logger object.
      */






      private java.lang.String arRoleName;
      private java.lang.String arRoleDesc;
      private java.sql.Date arCreatedWhen;
      private java.lang.String arCreatedBy;
      private java.sql.Date arChangedWhen;
      private java.lang.String arChangedBy;

      /**
      * Default constructor.
      */
      public AppRole() {
      }

      /**
      * Value object constructor.
      */
      public AppRole(com.airit.fidsdb.business.AppRoleObj value) {
      setArRoleName(value.getArRoleName());
      setArRoleDesc(value.getArRoleDesc());
      setArCreatedWhen(value.getArCreatedWhen());
      setArCreatedBy(value.getArCreatedBy());
      setArChangedWhen(value.getArChangedWhen());
      setArChangedBy(value.getArChangedBy());
      }




      /**
      * Returns the value of the arRoleName property.
      *
      */
      @Column(name = "AR_ROLE_NAME")
      @Id(generate = GeneratorType.NONE)
      public java.lang.String getArRoleName() {
      return arRoleName;
      }

      /**
      * Sets the value of the arRoleName property.
      *
      * @param arRoleName the value for the arRoleName property
      */
      public void setArRoleName(java.lang.String arRoleName) {
      this.arRoleName = arRoleName;
      }

      /**
      * Returns the value of the arRoleDesc property.
      *
      */
      @Column(name = "AR_ROLE_DESC")
      public java.lang.String getArRoleDesc() {
      return arRoleDesc;
      }

      /**
      * Sets the value of the arRoleDesc property.
      *
      * @param arRoleDesc the value for the arRoleDesc property
      */
      public void setArRoleDesc(java.lang.String arRoleDesc) {
      this.arRoleDesc = arRoleDesc;
      }

      /**
      * Returns the value of the arCreatedWhen property.
      *
      */
      @Column(name = "AR_CREATED_WHEN")
      public java.sql.Date getArCreatedWhen() {
      return arCreatedWhen;
      }

      /**
      * Sets the value of the arCreatedWhen property.
      *
      * @param arCreatedWhen the value for the arCreatedWhen property
      */
      public void setArCreatedWhen(java.sql.Date arCreatedWhen) {
      this.arCreatedWhen = arCreatedWhen;
      }

      /**
      * Returns the value of the arCreatedBy property.
      *
      */
      @Column(name = "AR_CREATED_BY")
      public java.lang.String getArCreatedBy() {
      return arCreatedBy;
      }

      /**
      * Sets the value of the arCreatedBy property.
      *
      * @param arCreatedBy the value for the arCreatedBy property
      */
      public void setArCreatedBy(java.lang.String arCreatedBy) {
      this.arCreatedBy = arCreatedBy;
      }

      /**
      * Returns the value of the arChangedWhen property.
      *
      */
      @Column(name = "AR_CHANGED_WHEN")
      public java.sql.Date getArChangedWhen() {
      return arChangedWhen;
      }

      /**
      * Sets the value of the arChangedWhen property.
      *
      * @param arChangedWhen the value for the arChangedWhen property
      */
      public void setArChangedWhen(java.sql.Date arChangedWhen) {
      this.arChangedWhen = arChangedWhen;
      }

      /**
      * Returns the value of the arChangedBy property.
      *
      */
      @Column(name = "AR_CHANGED_BY")
      public java.lang.String getArChangedBy() {
      return arChangedBy;
      }

      /**
      * Sets the value of the arChangedBy property.
      *
      * @param arChangedBy the value for the arChangedBy property
      */
      public void setArChangedBy(java.lang.String arChangedBy) {
      this.arChangedBy = arChangedBy;
      }


      }


      NOTE: The two foreign keys are the composite key for APPROLEFUNCTION.When i try this i get a null value exception. I am using
      jboss 4.03 beta 1.