OpenJPA
  1. OpenJPA
  2. OPENJPA-456

Missed to validate the column name length for Join Column

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.1.0, 1.2.0
    • Component/s: jdbc
    • Labels:
      None

      Description

      In the PersistenceMappingDefault.populateJoinColumn() method, it missed the call to validate the column length. Consequencely the column length that was longer than DB2's max column length resulted an invalid column length exception .

      The fix wil be:

      public void populateJoinColumn(FieldMapping fm, Table local, Table foreign,
      Column col, Object target, int pos, int cols)

      { // only use spec defaults with column targets if (!(target instanceof Column)) return; // if this is a bidi relation, prefix with inverse field name, else // prefix with owning entity name FieldMapping[] inverses = fm.getInverseMappings(); String name; if (inverses.length > 0) name = inverses[0].getName(); else name = fm.getDefiningMapping().getTypeAlias(); // suffix with '_' + target column name += "_" + ((Column) target).getName(); name = dict.getValidColumnName(name, foreign); ===> add this call before set the name to the column. col.setName(name); }
      1. openjpa_456_2.patch
        1.0 kB
        Teresa Kan
      2. OPENJPA-456.patch
        0.6 kB
        Teresa Kan

        Activity

        Hide
        Teresa Kan added a comment -

        Attach the patch..

        Show
        Teresa Kan added a comment - Attach the patch..
        Hide
        Teresa Kan added a comment -

        With my current fix(OPENJPA-456) which put the getValidColumnName() in the PersistenctMappingDefault..populateJoinColumn(). The output will be like this:

        ===PersitendceMappingDefault.populateJoinColumn(), name before conversion=RelationToHandlerMapInstance_id
        ===PersitendceMappingDefault.populateJoinColumn(), name after conversion=RELATIONTOHANDLERMAPINSTANCE_I

        If I modified the code to shorten the name first before append the targetName ("_ID"), then the output looks like this:

        ===PersitendceMappingDefault.populateJoinColumn(), tempname =RelationToHandlerMapInstanc
        ===PersitendceMappingDefault.populateJoinColumn(), name before conversion=RelationToHandlerMapInstanc_id
        ===PersitendceMappingDefault.populateJoinColumn(), name after conversion=RELATIONTOHANDLERMAPINSTANC_ID

        I think the latest solution is better. It preserves the _ID at the end. For current solution will lost the _ID at the end if the max column name is much shorter than the initial name.
        The attach patch provides the latest solution..

        Show
        Teresa Kan added a comment - With my current fix( OPENJPA-456 ) which put the getValidColumnName() in the PersistenctMappingDefault..populateJoinColumn(). The output will be like this: ===PersitendceMappingDefault.populateJoinColumn(), name before conversion=RelationToHandlerMapInstance_id ===PersitendceMappingDefault.populateJoinColumn(), name after conversion=RELATIONTOHANDLERMAPINSTANCE_I If I modified the code to shorten the name first before append the targetName ("_ID"), then the output looks like this: ===PersitendceMappingDefault.populateJoinColumn(), tempname =RelationToHandlerMapInstanc ===PersitendceMappingDefault.populateJoinColumn(), name before conversion=RelationToHandlerMapInstanc_id ===PersitendceMappingDefault.populateJoinColumn(), name after conversion=RELATIONTOHANDLERMAPINSTANC_ID I think the latest solution is better. It preserves the _ID at the end. For current solution will lost the _ID at the end if the max column name is much shorter than the initial name. The attach patch provides the latest solution..
        Hide
        Michael Dick added a comment -

        Closing old issue which was integrated with revision 603633 on 12-12-2008

        Show
        Michael Dick added a comment - Closing old issue which was integrated with revision 603633 on 12-12-2008

          People

          • Assignee:
            Michael Dick
            Reporter:
            Teresa Kan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development