OpenJPA
  1. OpenJPA
  2. OPENJPA-421

OpenJPA generates bad SQL before configuration fully populated

    Details

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

      Description

      When openjpa.jdbc.DBDictionary is set in persistence.xml file, OpenJPA creates a new DBDictionary instance by loading the class specified in the properties without trying to connect to database. It leaves version related configuration unset until the first connection to the database and creates the window of referencing partial properties in the DBDictionary. The problem happens when the first sql statement gets constructed within this window with lack of the knowledge of the version of the database.

      For example, with the setting that described below, BIGINT was generated in the
      SQL statement to be run on DB2 z/OS V8 and failed to execute because BIGINT was not supported on that version of z/OS DB2.

      1. commenting out the setting of "openjpa.jdbc.SynchronizeMappings".
      2. configure the connection properties to a z/OS database
      3. issuing a statement similar to the following to generate SQL statement with
      "CAST(? AS BIGINT)".

      Here is the testcase that I use to create the problem:
      {
      EntityManagerFactory emf1 =
      Persistence.createEntityManagerFactory("demo");
      EntityManager em1 = emf1.createEntityManager();
      em1.getTransaction().begin();
      Order o3 = (Order) em1.createQuery(
      "select o from Order o where o.oid = 68").getSingleResult();
      ...
      }

      ==>
      SELECT t0.oid, t0.version, t0.amount, t0.delivered FROM Order t0
      WHERE (t0.oid = CAST(? AS BIGINT)) optimize for 1 row [params=(long) 68]

        Activity

        Hide
        Daniel Lee added a comment -

        This patch applies to both trunk and branch.

        Show
        Daniel Lee added a comment - This patch applies to both trunk and branch.
        Hide
        Craig L Russell added a comment -

        Minor formatting issue.
        + conn = ds.getConnection(conf.getConnectionUserName()
        + , conf.getConnectionPassword());
        + else
        + conn = ds.getConnection(conf.getConnection2UserName()
        + , conf.getConnection2Password());

        should be
        + conn = ds.getConnection(conf.getConnectionUserName(),
        + conf.getConnectionPassword());
        + else
        + conn = ds.getConnection(conf.getConnection2UserName(),
        + conf.getConnection2Password());

        I'd like to see a comment when swallowing a possible exception closing the connection. Since swallowing exceptions generally is bad practice, it would help to comment...
        + try

        { + conn.close(); + }

        catch (SQLException se)

        { // ignore any exception since the connection is not going to be used anyway + }
        Show
        Craig L Russell added a comment - Minor formatting issue. + conn = ds.getConnection(conf.getConnectionUserName() + , conf.getConnectionPassword()); + else + conn = ds.getConnection(conf.getConnection2UserName() + , conf.getConnection2Password()); should be + conn = ds.getConnection(conf.getConnectionUserName(), + conf.getConnectionPassword()); + else + conn = ds.getConnection(conf.getConnection2UserName(), + conf.getConnection2Password()); I'd like to see a comment when swallowing a possible exception closing the connection. Since swallowing exceptions generally is bad practice, it would help to comment... + try { + conn.close(); + } catch (SQLException se) { // ignore any exception since the connection is not going to be used anyway + }
        Hide
        Kevin Sutter added a comment -

        Something seems to be wrong with this patch... Not sure how Craig can see it okay. It's formatted funny. And, when I attempt to apply it to my project, I get an "invalid patch format" error.

        Show
        Kevin Sutter added a comment - Something seems to be wrong with this patch... Not sure how Craig can see it okay. It's formatted funny. And, when I attempt to apply it to my project, I get an "invalid patch format" error.
        Hide
        Michael Dick added a comment -

        I think I've fixed the patch (it works for me on Linux at least). Attaching the updated patch.

        Show
        Michael Dick added a comment - I think I've fixed the patch (it works for me on Linux at least). Attaching the updated patch.
        Hide
        Kevin Sutter added a comment -

        Okay, I was able to cut-and-paste my way to happiness with this patch... But, in the future, we need to ensure that patches posted to JIRA issues are readable and appliable. Thanks. I will be committing the changes soon...

        Show
        Kevin Sutter added a comment - Okay, I was able to cut-and-paste my way to happiness with this patch... But, in the future, we need to ensure that patches posted to JIRA issues are readable and appliable. Thanks. I will be committing the changes soon...
        Hide
        Daniel Lee added a comment -

        notepad reads it okay but not emacs. emacs will be used in addition to verify the patch in the future.

        Show
        Daniel Lee added a comment - notepad reads it okay but not emacs. emacs will be used in addition to verify the patch in the future.
        Hide
        Daniel Lee added a comment -

        Thanks for the correction.

        Show
        Daniel Lee added a comment - Thanks for the correction.
        Hide
        Kevin Sutter added a comment -

        Resolved via SVN #589723 for 1.0.1 and 1.1.0 branches.

        Show
        Kevin Sutter added a comment - Resolved via SVN #589723 for 1.0.1 and 1.1.0 branches.

          People

          • Assignee:
            Daniel Lee
            Reporter:
            Daniel Lee
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development