OpenJPA
  1. OpenJPA
  2. OPENJPA-505

CLONE -Incorrect Oracle DDL Generation for integer types since OPENJPA-455

    Details

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

      Description

      Since the fix for 455, I've found a problem. Oracle has a NUMBER
      column type, which may be specified with sizes, eg: NUMBER(7),
      or NUMBER(9,3), but may also be unsized, eg: NUMBER. Since the
      fix for 455, the new code is failing to process the "NUMBER

      {0}" template
      for non-sized columns, so the DDL sent to the DBMS is like:

      CREATE TABLE ABSTRACTMAPPEDAPPIDSUPER ( ..., VERSN NUMBER{0}

      , ...

      which needless to say, dies.

      A change I made to DBDictionary, that fixed this for me is:

      protected String insertSize(String typeName, String size) {
      if(StringUtils.isEmpty(size)) {

      int idx = typeName.indexOf("

      {0}"); // remove the size token if not needed...
      if (idx != -1) { return typeName.substring(0,idx); }
      return typeName;
      }

      int idx = typeName.indexOf("{0}

      ");
      ...

      ie:

      Index: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
      ===================================================================
      — openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (revision 610999)
      +++ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (working copy)
      @@ -1648,8 +1648,13 @@
      */
      protected String insertSize(String typeName, String size) {
      if(StringUtils.isEmpty(size))

      { - return typeName; - }


      +
      + int idx = typeName.indexOf("

      {0}");
      + if (idx != -1) { + return typeName.substring(0,idx); + }
      + return typeName;
      + }

      int idx = typeName.indexOf("{0}

      ");
      if (idx != -1) {

      Please let me know what you think, and how to absorb this
      change, or it's purpose. thanks,
      Joe Weinstein at BEA Systems

      1. my-change.patch
        0.8 kB
        Joe Weinstein

        Issue Links

          Activity

          Joe Weinstein created issue -
          Joe Weinstein made changes -
          Field Original Value New Value
          Link This issue is a clone of OPENJPA-455 [ OPENJPA-455 ]
          Joe Weinstein made changes -
          Summary CLONE -Incorrect MySQL DDL Generation for integer types CLONE -Incorrect Oracle DDL Generation for integer types since OPENJPA-455
          Description Opening a JIRA report on Tim's behalf.

          I turned the schema tool loose on a MySQL production database this
          afternoon and it failed. The essence of the problem appears that DDL was
          being generated with a type declaration of this form:

          int unsigned(10)

          In MySQL, the proper form is:

          int(10) unsigned

          viz:

          ALTER TABLE fubar MODIFY col1 int(10) unsigned;

          Checking other options indicates that similar constructs such as CREATE
          TABLE are likewise defective.

          I looked at the svn trunk head source code in
          org.apache.openjpa.jdbc.sql.MySQLDictionary.java and the parent class
          DBDictionary.java. The offending method appears to be:

          1508: public String getTypeName(Column col)

          This method has no override in MySQLDictionary, but apparently needs
          one. I think it's a minor mod, but I'm not currently set up to build and
          test in the environment where the offending database exists.

          This is a SEVERE error. It causes generation of defective SQL for
          SQL-generating options and causes live updates to schemas to fail.

          I don't have a Jira login at present, so if someone could log this, it
          would be appreciated.

            Thanks,

             Tim Holloway
          Since the fix for 455, I've found a problem. Oracle has a NUMBER
          column type, which may be specified with sizes, eg: NUMBER(7),
          or NUMBER(9,3), but may also be unsized, eg: NUMBER. Since the
          fix for 455, the new code is failing to process the "NUMBER{0}" template
          for non-sized columns, so the DDL sent to the DBMS is like:

          CREATE TABLE ABSTRACTMAPPEDAPPIDSUPER ( ..., VERSN NUMBER{0}, ...

          which needless to say, dies.

          A change I made to DBDictionary, that fixed this for me is:

              protected String insertSize(String typeName, String size) {
                  if(StringUtils.isEmpty(size)) {

                    int idx = typeName.indexOf("{0}"); // remove the size token if not needed...
                    if (idx != -1) {
                      return typeName.substring(0,idx);
                    }
                    return typeName;
                  }

                  int idx = typeName.indexOf("{0}");
          ...


          ie:

          Index: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
          ===================================================================
          --- openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (revision 610999)
          +++ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (working copy)
          @@ -1648,8 +1648,13 @@
                */
               protected String insertSize(String typeName, String size) {
                  if(StringUtils.isEmpty(size)) {
          - return typeName;
          - }
          +
          + int idx = typeName.indexOf("{0}");
          + if (idx != -1) {
          + return typeName.substring(0,idx);
          + }
          + return typeName;
          + }

                   int idx = typeName.indexOf("{0}");
                   if (idx != -1) {

          Please let me know what you think, and how to absorb this
          change, or it's purpose. thanks,
          Joe Weinstein at BEA Systems
          Joe Weinstein made changes -
          Attachment my-change.patch [ 12374295 ]
          Hide
          Patrick Linskey added a comment -

          Changing affected version information since OPENJPA-455 was not in the 1.0.x line.

          Show
          Patrick Linskey added a comment - Changing affected version information since OPENJPA-455 was not in the 1.0.x line.
          Patrick Linskey made changes -
          Affects Version/s 1.0.0 [ 12312341 ]
          Affects Version/s 1.1.0 [ 12312344 ]
          Affects Version/s 1.0.1 [ 12312687 ]
          Patrick Linskey made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          1d 3h 18m 1 Patrick Linskey 31/Jan/08 00:41
          Resolved Resolved Closed Closed
          768d 17h 50m 1 Donald Woods 09/Mar/10 18:32

            People

            • Assignee:
              Michael Dick
              Reporter:
              Joe Weinstein
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development