OpenJPA
  1. OpenJPA
  2. OPENJPA-427

PostgresDictionary should set "63" as "maxAutoAssignNameLength".

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.0.0, 1.1.0
    • Fix Version/s: 1.1.0
    • Component/s: sql
    • Labels:
      None
    • Environment:
      PostgreSQL 8.1.

      Description

      PostgresDictionary should set "63" (or something correct) as "maxAutoAssignNameLength", in order to let DBDictionary#getGeneratedKeySequenceName() generate correct names for IDENTITY sequences.

      OpenJPA trims IDENTITY sequence names longer than 32 characters, while PostgreSQL uses longer names for BIGSERIAL sequences. So, persisting entities with @Id column with GenerationType.IDENTITY often results in a database error such as :
      org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR: relation "x_school_membershi_entityid_seq" does not exist

      {prepstmnt 2398193 SELECT CURRVAL(X_SCHOOL_TRANSFER_entityId_SEQ')}

      [code=0, state=42P01]

      The followings are the examples. "OK"s are the sequence names which PostgreSQL uses. "NG"s are those which OpenJPA attempts to use.

      Ex.1 -
      Table : X_SCHOOL_TRANSFER_EVENT
      BIGSERIAL Column : ENTITYID
      OK : X_SCHOOL_TRANSFER_EVENT_ENTITY_ID_SEQ
      NG : 'X_SCHOOL_TRANSFER__ENTITYID_SEQ

      Ex.2 -
      Table : X_SCHOOL_MEMBERSHIP
      BIGSERIAL Column : ENTITYID
      OK : X_SCHOOL_MEMBERSHIP_ENTITYID_SEQ
      NG : X_SCHOOL_MEMBERSHI_ENTITYID_SEQ

      1. mychanges.patch
        0.6 kB
        Ryosuke Iwata

        Activity

        Ryosuke Iwata created issue -
        Hide
        Ryosuke Iwata added a comment -

        I created and attached below a patch to clarify what I'm thinking is to be done to fix this issue : it's simply add "maxAutoAssignNameLength = 63;" to the codes in the constructor of PostgresDictionary.

        I've not tested the patch, because currently I don't have any environment to build OpenJPA.
        I expect that my fix will work, because, according to the source comment, PostgresDictionary uses getGeneratedKeySequenceName() which depends on the value of "maxAutoAssignNameLength" to obtain last generated key value.

        And, I'm not sure if the value "63" is suitable for "maxAutoAssignNameLength".

        I hope someone would fix if there's something wrong in my patch... m(_ _)m

        Thank you.

        Show
        Ryosuke Iwata added a comment - I created and attached below a patch to clarify what I'm thinking is to be done to fix this issue : it's simply add "maxAutoAssignNameLength = 63;" to the codes in the constructor of PostgresDictionary. I've not tested the patch, because currently I don't have any environment to build OpenJPA. I expect that my fix will work, because, according to the source comment, PostgresDictionary uses getGeneratedKeySequenceName() which depends on the value of "maxAutoAssignNameLength" to obtain last generated key value. And, I'm not sure if the value "63" is suitable for "maxAutoAssignNameLength". I hope someone would fix if there's something wrong in my patch... m(_ _)m Thank you.
        Ryosuke Iwata made changes -
        Field Original Value New Value
        Attachment mychanges.patch [ 12368940 ]
        Hide
        Craig L Russell added a comment -

        This patch seems innocuous, and I'd like to check it in without testing.

        Any objection to putting it into trunk?

        How about 1.0.x?

        How about 1.0.1? Do we think 1.0.1 is finished?

        Show
        Craig L Russell added a comment - This patch seems innocuous, and I'd like to check it in without testing. Any objection to putting it into trunk? How about 1.0.x? How about 1.0.1? Do we think 1.0.1 is finished?
        Hide
        Patrick Linskey added a comment -

        No objection to putting it into trunk.

        I don't see any need to put it into 1.0.x or 1.0.1. Personally, I'm very conservative about putting any changes at all into maintenance releases, since there can always be unintended side-effects that we should be insulating our maintenance-release-consumers from.

        Show
        Patrick Linskey added a comment - No objection to putting it into trunk. I don't see any need to put it into 1.0.x or 1.0.1. Personally, I'm very conservative about putting any changes at all into maintenance releases, since there can always be unintended side-effects that we should be insulating our maintenance-release-consumers from.
        Hide
        Michael Dick added a comment -

        No objections to trunk or 1.0.x.

        I don't think we need it in 1.0.1, but Albert's the judge, jury, etc.

        Show
        Michael Dick added a comment - No objections to trunk or 1.0.x. I don't think we need it in 1.0.1, but Albert's the judge, jury, etc.
        Hide
        Ryosuke Iwata added a comment -

        I built OpenJPA with my patch and deployed my EAR with the private build.
        Finally, @Entity objects with IDENTITY key generation no longer cause exceptions that I reported. IDENTITY sequence names seem to be handled correctly. And, for now, I don't see any side effects.

        I hope that this patch is included as soon as possible, because our product needs IDENTITY key generation.

        Thank you.

        Show
        Ryosuke Iwata added a comment - I built OpenJPA with my patch and deployed my EAR with the private build. Finally, @Entity objects with IDENTITY key generation no longer cause exceptions that I reported. IDENTITY sequence names seem to be handled correctly. And, for now, I don't see any side effects. I hope that this patch is included as soon as possible, because our product needs IDENTITY key generation. Thank you.
        Hide
        Patrick Linskey added a comment -

        Note that you should be able to do this without a patch by setting the following configuration option:

        <property name="openjpa.jdbc.DBDictionary" value="MaxAutoAssignNameLength=63"/>

        Show
        Patrick Linskey added a comment - Note that you should be able to do this without a patch by setting the following configuration option: <property name="openjpa.jdbc.DBDictionary" value="MaxAutoAssignNameLength=63"/>
        Hide
        Ryosuke Iwata added a comment -

        Thank you Patrick,

        I'm sorry that I missed it in the manual.

        Show
        Ryosuke Iwata added a comment - Thank you Patrick, I'm sorry that I missed it in the manual.
        Hide
        Craig L Russell added a comment -

        Checked in the patch supplied by Ryosuke Iwata.

        svn commit -m "OPENJPA-427 Change maxAutoAssignNameLength to 63 for PostgreSQL"
        Sending sql/PostgresDictionary.java
        Transmitting file data .
        Committed revision 595383.

        Show
        Craig L Russell added a comment - Checked in the patch supplied by Ryosuke Iwata. svn commit -m " OPENJPA-427 Change maxAutoAssignNameLength to 63 for PostgreSQL" Sending sql/PostgresDictionary.java Transmitting file data . Committed revision 595383.
        Craig L Russell made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.1.0 [ 12312344 ]
        Donald Woods made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Ryosuke Iwata
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development