Announcement Announcement Module
Collapse
No announcement yet.
Issue with MS-SQL database foreign key relationships when using Reverse Engineer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with MS-SQL database foreign key relationships when using Reverse Engineer

    I have a lookup table e.g. country table , which has a foreign key relationship with another table e.g. Address.
    when a new address record inserted into the table , the country code from country lookup table should be used and is enforced through the foreign key relationship. on the other hand when a record inserted into the country table there should not be restriction from addres table.

    when using the reverse engineer command, It was successfully able to connect to the existing dabase and created the dbre.xml with right fields & relationship but the enity objects are NOT created with correct relationship for the lookup type objects causing the create operation for the loop up table to fail.

    Below is the snipped from generated dbre.xml

    <table alias="dbo" name="MCDRP02_CD_B2C_SOURCE_CODE">
    <column name="CDRP02_SOURCE_C" primaryKey="true" required="true" scale="0" size="19" type="3,decimal"/><column name="CDRP02_SOURCE_X" primaryKey="false" required="false" scale="0" size="255" type="12,varchar"/>
    <column name="CDRP02_LAST_UPDT_S" primaryKey="false" required="true" scale="3" size="23" type="93,datetime"/>
    <column name="CDRP02_LAST_UPDT_USER_C" primaryKey="false" required="true" scale="0" size="8" type="12,varchar"/>
    <column name="CDRP02_DSP_PWD_CHGSCR_F" primaryKey="false" required="true" scale="0" size="1" type="1,char"/>
    <foreign-key foreignTable="MCDRP04_COMMON_APPLIC_PROFILE" name="MCDRP04_MCDRP02_F1"
    onDelete="restrict" onUpdate="restrict">
    <option key="foreignSchemaName" value="dbo"/>
    <option key="exported" value="true"/>
    <reference foreign="CDRP02_SOURCE_C" local="CDRP02_SOURCE_C"/>
    </foreign-key>
    <unique name="MCDRP021">
    <unique-column name="CDRP02_SOURCE_C"/>
    </unique>
    </table>

    The Entity object : Mcdrp02CdB2cSourceCode_Roo_Jpa_Entity.aj

    privileged aspect Mcdrp02CdB2cSourceCode_Roo_DbManaged {

    @OneToMany(mappedBy = "cdrp02SourceC")
    private Set<Mcdrp04CommonApplicProfile> Mcdrp02CdB2cSourceCode.mcdrp04CommonApplicProfiles ;

    @Column(name = "CDRP02_SOURCE_X", length = 255)
    private String Mcdrp02CdB2cSourceCode.cdrp02SourceX;

    @Column(name = "CDRP02_CREATE_DATE_S")
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date Mcdrp02CdB2cSourceCode.cdrp02CreateDateS;

    @Column(name = "CDRP02_CREATE_USER_C", length = 8)
    @NotNull
    private String Mcdrp02CdB2cSourceCode.cdrp02CreateUserC;

    @Column(name = "CDRP02_LAST_UPDT_S")
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date Mcdrp02CdB2cSourceCode.cdrp02LastUpdtS;

    @Column(name = "CDRP02_LAST_UPDT_USER_C", length = 8)
    @NotNull
    private String Mcdrp02CdB2cSourceCode.cdrp02LastUpdtUserC;

    @Column(name = "CDRP02_DSP_PWD_CHGSCR_F")
    @NotNull
    private Character Mcdrp02CdB2cSourceCode.cdrp02DspPwdChgscrF;

    public Set<Mcdrp04CommonApplicProfile> Mcdrp02CdB2cSourceCode.getMcdrp04CommonApplicProfi les() {
    return mcdrp04CommonApplicProfiles;
    }

    public void Mcdrp02CdB2cSourceCode.setMcdrp04CommonApplicProfi les(Set<Mcdrp04
    CommonApplicProfile> mcdrp04CommonApplicProfiles) {
    this.mcdrp04CommonApplicProfiles = mcdrp04CommonApplicProfiles;
    }

    public String Mcdrp02CdB2cSourceCode.getCdrp02SourceX() {
    return cdrp02SourceX;
    }

    public void Mcdrp02CdB2cSourceCode.setCdrp02SourceX(String cdrp02SourceX) {
    this.cdrp02SourceX = cdrp02SourceX;
    }
    ........

    }



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


    Because of the above relationship , when created the mvc screens to test the CRUD opertion it failed.

    1. The generated screens when doesn't even display the source code field, which is the primary key

    2. when try to bring the edit the lookup object , It's trying to load all the common profile records and runs out- memory error.

    Any help will be appreciated.

    thanks,
    Logan.

  • #2
    Please confiirm that in the absence of an MVC layer your entity relationships are correct in JPA terms after dbre-ing your MySQL Db?
    Alan

    Comment


    • #3
      Thanks Alan for your response.

      No , the JPA entity didn't have the correct relationship.
      Below is the code snippet code , which i have also highlighted above under Mcdrp02CdB2cSourceCode_Roo_Jpa_Entity.aj

      { (@OneToMany(mappedBy = "cdrp02SourceC")
      private Set<Mcdrp04CommonApplicProfile> Mcdrp02CdB2cSourceCode.mcdrp04CommonApplicProfiles ;
      @Column(name = "CDRP02_SOURCE_X", length = 255)
      private String Mcdrp02CdB2cSourceCode.cdrp02SourceX; }


      The enity class shouldn't have the one-to-many relationship.

      thanks,
      Logan.

      Comment

      Working...
      X