Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2650

When SchemaFactory and useSchemaName=false is set, a schema name is incorrectly used.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.3, 2.3.0, 2.4.2
    • Fix Version/s: 2.2.3, 2.4.0, 2.4.2
    • Component/s: jdbc, sql
    • Labels:
      None

      Description

      When "openjpa.jdbc.SchemaFactory=native(ForeignKeys=true)" is set, this tells OpenJPA to do up-front schema validation, and allows OpenJPA to be able to learn about any schemas it can "see". When this happens, OpenJPA will use the schema when generating SQL statements. For example, if OpenJPA finds table A under schema Y, when generating SQL on table A, schema Y will be appended to the generated SQL (e.g. SELECT a.id from Y.A a....). Without this property, OpenJPA doesn't otherwise use a schema name if it is not specified (i.e. as per the number of ways defined by the JPA spec, or the OpenJPA proprietary options, e.g. openjpa.jdbc.Schema). OpenJPA offers a way to tell it to not use a schema name by using this property:

      "openjpa.jdbc.DBDictionary=useSchemaName=false"

      When this property is set, OpenJPA will not append the schema to generated SQL (e.g. SELECT a.id from A a....). However, I have found a case where OpenJPA incorrectly applies the schema name. To explain, take this Entity, note the TableGenerator:

      @Entity
      public class MyEntityTable implements Serializable {

      @Id
      @TableGenerator(name = "TABLE_GENERATOR", table = "MY_ID_TABLE",
      pkColumnName = "MY_PK_COLUMN",
      pkColumnValue="MY_PK_NAME",
      valueColumnName = "MY_VALUE_COLUMN")
      @GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GENERATOR")
      ......

      With this Entity and TableGenerator, the SQL to select and update the generated value should be:

      SELECT MY_VALUE_COLUMN FROM MY_ID_TABLE WHERE MY_PK_COLUMN = ?

      UPDATE MY_ID_TABLE SET MY_VALUE_COLUMN = ? WHERE MY_PK_COLUMN = ? AND MY_VALUE_COLUMN = ?

      However, with the above SchemaFactory, and 'useSchemaName=false' settings, the table 'MY_ID_TABLE' would have the schema name appended to it (e.g. if the schema name is Y, the SQL would contain "Y.MY_ID_TABLE"). For SQL statements on 'MyEntityTable' itself, the schema name is not added to the SQL. The issue is limited to SQL statements against the table 'MY_ID_TABLE'. This is do to a hole in the OpenJPA code that generates SQL for the 'MY_ID_TABLE'. That is, the particular area of code does not take into consideration the value of 'useSchemaName'.

      Thanks,

      Heath Thomann

        Activity

        Hide
        jpaheath Heath Thomann added a comment -

        Attaching a patch which contains a proposed fix and test.

        Thanks,

        Heath Thomann

        Show
        jpaheath Heath Thomann added a comment - Attaching a patch which contains a proposed fix and test. Thanks, Heath Thomann
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1756538 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1756538 ]

        OPENJPA-2650: When SchemaFactory and useSchemaName=false is set, a schema name is incorrectly used.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1756538 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1756538 ] OPENJPA-2650 : When SchemaFactory and useSchemaName=false is set, a schema name is incorrectly used.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1756539 from hthomann@apache.org in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1756539 ]

        OPENJPA-2650: When SchemaFactory and useSchemaName=false is set, a schema name is incorrectly used. Merged 2.2.x commit to trunk.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1756539 from hthomann@apache.org in branch 'openjpa/trunk' [ https://svn.apache.org/r1756539 ] OPENJPA-2650 : When SchemaFactory and useSchemaName=false is set, a schema name is incorrectly used. Merged 2.2.x commit to trunk.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1756728 from Francesco Chicchiriccò in branch 'openjpa/branches/2.3.x'
        [ https://svn.apache.org/r1756728 ]

        OPENJPA-2650 Applying the patch provided to the neglected 2.3.x branch

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1756728 from Francesco Chicchiriccò in branch 'openjpa/branches/2.3.x' [ https://svn.apache.org/r1756728 ] OPENJPA-2650 Applying the patch provided to the neglected 2.3.x branch
        Hide
        ilgrosso Francesco Chicchiriccò added a comment -

        Reopening to apply the same patch to the neglected 2.3.x branch

        Show
        ilgrosso Francesco Chicchiriccò added a comment - Reopening to apply the same patch to the neglected 2.3.x branch
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1757893 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1757893 ]

        OPENJPA-2650: Made a very simple test update to the test created for this JIRA.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1757893 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1757893 ] OPENJPA-2650 : Made a very simple test update to the test created for this JIRA.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1757894 from Heath Thomann in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1757894 ]

        OPENJPA-2650: Made a very simple test update to the test created for this JIRA.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1757894 from Heath Thomann in branch 'openjpa/trunk' [ https://svn.apache.org/r1757894 ] OPENJPA-2650 : Made a very simple test update to the test created for this JIRA.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1757895 from Heath Thomann in branch 'openjpa/branches/2.3.x'
        [ https://svn.apache.org/r1757895 ]

        OPENJPA-2650: Made a very simple test update to the test created for this JIRA.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1757895 from Heath Thomann in branch 'openjpa/branches/2.3.x' [ https://svn.apache.org/r1757895 ] OPENJPA-2650 : Made a very simple test update to the test created for this JIRA.

          People

          • Assignee:
            jpaheath Heath Thomann
            Reporter:
            jpaheath Heath Thomann
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development