OpenJPA
  1. OpenJPA
  2. OPENJPA-1682

TestSimpleXmlEntity.testId failed with invalid DB2 create table SQL statement

    Details

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

      Description

      TestSimpleXmlEntity.testId starts failing with the following exception against DB2:

      TestSimpleXmlEntity.testId View test details (org.apache.openjpa.persistence.xml)
      <openjpa-2.1.0-SNAPSHOT-r422266:951071 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: DB2 SQL Error: SQLCODE=-542, SQLSTATE=42831, SQLERRMC=NICKNAME_XML, DRIVER=3.50.152

      {stmnt 65405926 CREATE TABLE NickNames_xml (A_ID_xml INTEGER NOT NULL, nickName_xml VARCHAR(20), CONSTRAINT U_NCKNXML_A_ID_XML UNIQUE (A_ID_xml, nickName_xml))} [code=-542, state=42831]
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:556)
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:456)
      Please wait... Show details »
      « Hide details
      <openjpa-2.1.0-SNAPSHOT-r422266:951071 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: DB2 SQL Error: SQLCODE=-542, SQLSTATE=42831, SQLERRMC=NICKNAME_XML, DRIVER=3.50.152 {stmnt 65405926 CREATE TABLE NickNames_xml (A_ID_xml INTEGER NOT NULL, nickName_xml VARCHAR(20), CONSTRAINT U_NCKNXML_A_ID_XML UNIQUE (A_ID_xml, nickName_xml))}

      [code=-542, state=42831]
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:556)
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:456)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:155)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:159)
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:117)
      at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:199)
      at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:213)
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
      at org.apache.openjpa.persistence.test.SingleEMTestCase.setUp(SingleEMTestCase.java:47)
      at org.apache.openjpa.persistence.xml.TestSimpleXmlEntity.setUp(TestSimpleXmlEntity.java:28)
      at junit.framework.TestCase.runBare(TestCase.java:125)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:503)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:479)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.run(AbstractPersistenceTestCase.java:179)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
      Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: DB2 SQL Error: SQLCODE=-542, SQLSTATE=42831, SQLERRMC=NICKNAME_XML, DRIVER=3.50.152

      {stmnt 65405926 CREATE TABLE NickNames_xml (A_ID_xml INTEGER NOT NULL, nickName_xml VARCHAR(20), CONSTRAINT U_NCKNXML_A_ID_XML UNIQUE (A_ID_xml, nickName_xml))}

      [code=-542, state=42831]
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:257)
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:241)
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:70)
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingStatement.executeUpdate(LoggingConnectionDecorator.java:951)
      at org.apache.openjpa.lib.jdbc.DelegatingStatement.executeUpdate(DelegatingStatement.java:136)
      at org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1200)
      at org.apache.openjpa.jdbc.schema.SchemaTool.createTable(SchemaTool.java:956)
      at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:533)
      at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:348)
      at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:325)
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:504)
      ... 33 more

      The create table constraint requires nickName_xml be "NOT NULL"

      Albert Lee

        Issue Links

          Activity

          Hide
          Pinaki Poddar added a comment -

          Patch for database specific decision on whether to non-nullify a column on which a unique constraint has been placed.

          Show
          Pinaki Poddar added a comment - Patch for database specific decision on whether to non-nullify a column on which a unique constraint has been placed.
          Hide
          Pinaki Poddar added a comment -

          Can an unique column be nullable? The answer seems to vary across databases.

          The observed DB2 error -542 points that DB2 does not allow a unique column to be nullable.
          " column-name CANNOT BE A COLUMN OF A PRIMARY KEY, A UNIQUE CONSTRAINT, OR A PARENT KEY BECAUSE IT CAN CONTAIN NULL VALUES
          Explanation : The code is used to report that a column identified in a PRIMARY KEY, a UNIQUE constraint clause, or a parent key (via a REFERENCES clause) is defined to allow null values."

          While MySQL seems to allow a null value on a column with unique constraint.

          OpenJPA currently works in a way that an unique constraint on a column does not imply any nullability – positive or negative.
          Earlier (prior to revision 941362), we forced that an unique constraint on a column does imply non-nullability. But OPENJPA-1387 made the point that unique constraint should not imply non-nullable – whch I tend to agree and hence revision 941362 removed the implication.

          But as the current issue shows, we need to make this implication database dependent.

          Show
          Pinaki Poddar added a comment - Can an unique column be nullable? The answer seems to vary across databases. The observed DB2 error -542 points that DB2 does not allow a unique column to be nullable. " column-name CANNOT BE A COLUMN OF A PRIMARY KEY, A UNIQUE CONSTRAINT, OR A PARENT KEY BECAUSE IT CAN CONTAIN NULL VALUES Explanation : The code is used to report that a column identified in a PRIMARY KEY, a UNIQUE constraint clause, or a parent key (via a REFERENCES clause) is defined to allow null values." While MySQL seems to allow a null value on a column with unique constraint. OpenJPA currently works in a way that an unique constraint on a column does not imply any nullability – positive or negative. Earlier (prior to revision 941362), we forced that an unique constraint on a column does imply non-nullability. But OPENJPA-1387 made the point that unique constraint should not imply non-nullable – whch I tend to agree and hence revision 941362 removed the implication. But as the current issue shows, we need to make this implication database dependent.
          Hide
          Albert Lee added a comment -

          Tests Result from before and after r941362.
          ------------------------------
          openjpa.trunk.941084

          Results :

          Failed tests:
          testQueryQualifiedId(org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex4.TestSpec10_1_27_Ex4)

          Tests in error:
          testGroupByEmbed(org.apache.openjpa.persistence.embed.TestEmbeddable)
          testMultiThreadedNativeSequences(org.apache.openjpa.persistence.sequence.TestSequence)
          testSimple(org.apache.openjpa.persistence.kernel.TestSavepoints)

          Tests run: 2451, Failures: 1, Errors: 3, Skipped: 0
          ------------------------------
          openjpa.trunk.941362

          Results :

          Failed tests:
          testQueryQualifiedId(org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex4.TestSpec10_1_27_Ex4)

          Tests in error:
          testId(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity)
          testNamedQueryInXmlNamedEntity(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity)
          testNamedQueryInXmlUsingShortClassName(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity)
          testNamedEntityInDynamicQuery(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity)
          testShortClassNameInDynamicQuery(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity)
          testOverriddenEntityName(org.apache.openjpa.persistence.xml.TestXmlOverrideEntity)
          testOptionalAttributeOverride(org.apache.openjpa.persistence.xml.TestXmlOverrideEntity)
          testColumnOverride(org.apache.openjpa.persistence.xml.TestXmlOverrideEntity)
          testTableName(org.apache.openjpa.persistence.delimited.identifiers.TestDelimitedIdentifiers)
          testMultiThreadedNativeSequences(org.apache.openjpa.persistence.sequence.TestSequence)
          testCreateF(org.apache.openjpa.persistence.delimited.identifiers.noschema.TestNoSchemaManualDelimId)
          testCreateF2(org.apache.openjpa.persistence.delimited.identifiers.noschema.TestNoSchemaManualDelimId)
          testTableName(org.apache.openjpa.persistence.delimited.identifiers.xml.TestXmlDelimitedIdentifiers)
          testBasicEmbedAttrOverride(org.apache.openjpa.persistence.embed.attrOverrides.TestAttrOverridesXml)
          testXMLEntityWithAnnotatedOverrideEmbed(org.apache.openjpa.persistence.embed.attrOverrides.TestAttrOverridesXml
          testMapping(org.apache.openjpa.persistence.jdbc.unique.TestUniqueConstraint)
          testMixedOrmAnno(org.apache.openjpa.persistence.TestMixedMappingLocation)
          testSimple(org.apache.openjpa.persistence.kernel.TestSavepoints)
          testMapping(org.apache.openjpa.persistence.jdbc.unique.TestUniqueConstraintWithXMLDescriptor)
          testCreateF(org.apache.openjpa.persistence.delimited.identifiers.TestManualDelimId)
          testCreateF2(org.apache.openjpa.persistence.delimited.identifiers.TestManualDelimId)
          testMapping(org.apache.openjpa.persistence.jdbc.unique.TestNamedUniqueConstraint)
          testNullOnOptionalFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnNonOptionalFieldIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNotNullOnOptionalFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNotNullOnNonOptionalFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnNullableColumnAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnNonNullableColumnIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNotNullOnNullableColumnIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNotNullOnNonNullableColumnIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnOptionalBlobFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnNonOptionalBlobFieldIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnNullableBlobColumnAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testNullOnNonNullableBlobColumnIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testX(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testUniqueStringColumnCanBeNull(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testUniqueStringColumnAsNull(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testUniqueStringColumnAsEmpty(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity)
          testMapping(org.apache.openjpa.persistence.jdbc.unique.TestNamedUniqueConstraintWithXMLDescriptor)

          Tests run: 2454, Failures: 1, Errors: 39, Skipped: 0

          Show
          Albert Lee added a comment - Tests Result from before and after r941362. ------------------------------ openjpa.trunk.941084 Results : Failed tests: testQueryQualifiedId(org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex4.TestSpec10_1_27_Ex4) Tests in error: testGroupByEmbed(org.apache.openjpa.persistence.embed.TestEmbeddable) testMultiThreadedNativeSequences(org.apache.openjpa.persistence.sequence.TestSequence) testSimple(org.apache.openjpa.persistence.kernel.TestSavepoints) Tests run: 2451, Failures: 1, Errors: 3, Skipped: 0 ------------------------------ openjpa.trunk.941362 Results : Failed tests: testQueryQualifiedId(org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex4.TestSpec10_1_27_Ex4) Tests in error: testId(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity) testNamedQueryInXmlNamedEntity(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity) testNamedQueryInXmlUsingShortClassName(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity) testNamedEntityInDynamicQuery(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity) testShortClassNameInDynamicQuery(org.apache.openjpa.persistence.xml.TestSimpleXmlEntity) testOverriddenEntityName(org.apache.openjpa.persistence.xml.TestXmlOverrideEntity) testOptionalAttributeOverride(org.apache.openjpa.persistence.xml.TestXmlOverrideEntity) testColumnOverride(org.apache.openjpa.persistence.xml.TestXmlOverrideEntity) testTableName(org.apache.openjpa.persistence.delimited.identifiers.TestDelimitedIdentifiers) testMultiThreadedNativeSequences(org.apache.openjpa.persistence.sequence.TestSequence) testCreateF(org.apache.openjpa.persistence.delimited.identifiers.noschema.TestNoSchemaManualDelimId) testCreateF2(org.apache.openjpa.persistence.delimited.identifiers.noschema.TestNoSchemaManualDelimId) testTableName(org.apache.openjpa.persistence.delimited.identifiers.xml.TestXmlDelimitedIdentifiers) testBasicEmbedAttrOverride(org.apache.openjpa.persistence.embed.attrOverrides.TestAttrOverridesXml) testXMLEntityWithAnnotatedOverrideEmbed(org.apache.openjpa.persistence.embed.attrOverrides.TestAttrOverridesXml testMapping(org.apache.openjpa.persistence.jdbc.unique.TestUniqueConstraint) testMixedOrmAnno(org.apache.openjpa.persistence.TestMixedMappingLocation) testSimple(org.apache.openjpa.persistence.kernel.TestSavepoints) testMapping(org.apache.openjpa.persistence.jdbc.unique.TestUniqueConstraintWithXMLDescriptor) testCreateF(org.apache.openjpa.persistence.delimited.identifiers.TestManualDelimId) testCreateF2(org.apache.openjpa.persistence.delimited.identifiers.TestManualDelimId) testMapping(org.apache.openjpa.persistence.jdbc.unique.TestNamedUniqueConstraint) testNullOnOptionalFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnNonOptionalFieldIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNotNullOnOptionalFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNotNullOnNonOptionalFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnNullableColumnAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnNonNullableColumnIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNotNullOnNullableColumnIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNotNullOnNonNullableColumnIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnOptionalBlobFieldIsAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnNonOptionalBlobFieldIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnNullableBlobColumnAllowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testNullOnNonNullableBlobColumnIsDisallowed(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testX(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testUniqueStringColumnCanBeNull(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testUniqueStringColumnAsNull(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testUniqueStringColumnAsEmpty(org.apache.openjpa.persistence.nullity.TestBasicFieldNullity) testMapping(org.apache.openjpa.persistence.jdbc.unique.TestNamedUniqueConstraintWithXMLDescriptor) Tests run: 2454, Failures: 1, Errors: 39, Skipped: 0
          Hide
          Albert Lee added a comment -

          This regression is introduced under r941362 as part of the OPENJPA-1387 commit where Unique.addColumn() method was removed, hence the col.setNotNull(true) is not enforced.

          Albert Lee.

          Show
          Albert Lee added a comment - This regression is introduced under r941362 as part of the OPENJPA-1387 commit where Unique.addColumn() method was removed, hence the col.setNotNull(true) is not enforced. Albert Lee.
          Hide
          Albert Lee added a comment -

          Not sure why the following commit associate to this issue?

          ASF #935970 Tue Apr 20 11:58:23 EDT 2010 ppoddar OPENJPA-1682: Merge doc change from trunk
          Files Changed
          MODIFY /openjpa/branches/2.0.x/openjpa-project/src/doc/manual/jpa_overview_criteria.xml

          Show
          Albert Lee added a comment - Not sure why the following commit associate to this issue? ASF #935970 Tue Apr 20 11:58:23 EDT 2010 ppoddar OPENJPA-1682 : Merge doc change from trunk Files Changed MODIFY /openjpa/branches/2.0.x/openjpa-project/src/doc/manual/jpa_overview_criteria.xml

            People

            • Assignee:
              Pinaki Poddar
              Reporter:
              Albert Lee
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development