OpenJPA
  1. OpenJPA
  2. OPENJPA-2095

Unhandled exception thrown from within an Externalizer method causes incorrect/incomplete SQL to be generated/executed.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.3, 2.0.2, 2.1.2, 2.2.0
    • Fix Version/s: 1.2.3, 2.0.2, 2.1.2, 2.2.1, 2.3.0
    • Component/s: sql
    • Labels:
      None

      Description

      I've re-created an issue with Externalizers. That is, when the Externalizer method (i.e. the method listed in the @Externalizer) causes/throws an exception, OpenJPA generates, and executes, incorrect/incomplete SQL. To better explain, let me describe some test code snippets which are from the test I'll provide. First, take this entity:

      @Entity
      public class TestItem implements Serializable {
      .....
      @org.apache.openjpa.persistence.Persistent
      @org.apache.openjpa.persistence.Externalizer("check")
      private TestExternal ext;

      And take the following class TestExternal:

      public static class TestExternal {
      .....
      public String check() throws Exception {
      throw new PersistenceException("test exception externalizer");

      With this code, lets look at the case where we persist a new TestItem, and the case where we update an existing one. When we create a new TestItem and persist it, OpenJPA generates and executes the following SQL:

      INSERT INTO TESTITEM (data) VALUES

      However, this SQL should be generated:

      INSERT INTO TESTITEM (iref, data, ext, name) VALUES (?, ?, ?, ?)

      When we update an existing TestItem, OpenJPA generates, and executes, the following SQL:

      UPDATE TESTITEM SET data = ?

      However, this SQL should be generated:

      UPDATE TESTITEM SET data = ? WHERE iref = ?

      Because an unhandled exception is thrown by the Externalizer method, the transaction will be rolled back. However, if the SQL were to actually commit, every row in TestItem would be updated with the value in 'data'. Furthermore, in the case where there are hundreds/thousands of rows in the DB, the execution of the SQL may take a long time to complete and will maintain a lock on the TestItem table during the execution, possibly locking out other clients.

      I've included a simple test, named ExternalizerTest.zip, which demonstrates the issue.

      Thanks,

      Heath

        Issue Links

          Activity

          Hide
          Heath Thomann added a comment -

          Test to reproduce the issue described in the description.

          Show
          Heath Thomann added a comment - Test to reproduce the issue described in the description.
          Hide
          Helen Xu added a comment -

          it will throw class cast exception if OPENJPA-828 is not back ported

          Show
          Helen Xu added a comment - it will throw class cast exception if OPENJPA-828 is not back ported

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development