Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-569

Wrong working with sequences in multi-insertion of one entity

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:
      PostgreSQL 8.4.3, Ubuntu 10.04

      Description

      In unit test I wrote couple of insertions of one entity, but there is only one SELECT NEXTVAL('table_id_seq') query at the beggining. It seems that ID value for the second a other entities is somehow computed inside Doctrine. I think that it's wrong, because there could be another transactions with the same requests. And finally in the end of the script there is no refreshing of sequence value.

      I don't know it works in way how I describe or it is my fault in configuration.

      1. doctrine-sequence.tar.gz
        1 kB
        Václav Novotný
      2. log.sql
        10 kB
        Václav Novotný

        Activity

        Show
        Václav Novotný added a comment - Identity strategy is supported for PostgreSQL? http://www.doctrine-project.org/documentation/manual/2_0/dbal/basic-mapping#identifiers-/-primary-keys:id-generation-strategies
        Hide
        Roman S. Borschel added a comment - - edited

        Yes, IDENTITY on PostgreSQL means SERIAL.

        IDENTITY =

        MSSQL: IDENTITY
        MySQL: AUTO_INCREMENT
        PostgreSQL: SERIAL
        Oracle: not supported

        That is the current state. On Oracle it could be emulated with triggers or so but we have not dont that yet.

        More formally, the IDENTITY strategy means "An identity column whose (unique) value is automatically generated and assigned by the database on INSERT."

        Show
        Roman S. Borschel added a comment - - edited Yes, IDENTITY on PostgreSQL means SERIAL. IDENTITY = MSSQL: IDENTITY MySQL: AUTO_INCREMENT PostgreSQL: SERIAL Oracle: not supported That is the current state. On Oracle it could be emulated with triggers or so but we have not dont that yet. More formally, the IDENTITY strategy means "An identity column whose (unique) value is automatically generated and assigned by the database on INSERT."
        Hide
        Jan Tichý added a comment - - edited

        Hi Roman, current default value for allocationSize=10 is CONFUSING and may (and surely WILL) cause problems and misunderstoods for many people in future.

        The core of the problem is that we define table structure manually, separately from entity annotations. Many people do that. And while the default allocationSize is 10, I have to remember each time I write new table and new entity, that:

        a) I have to define each the sequence in database manually with INCREMENT BY 10
        b) OR I have to define in each entity manually the annotation for @SequenceGenerator - allocationSize=1
        c) OR I have to manually use strategy="IDENTITY", but according to documentation it is NOT supported by PostgreSQL

        Shortly, I have to remember and explicitly WRITE SOMETHING as to avoid problems caused by wrong default value and to get myself to common default (increment by 1) considered by common meaning

        I think that default value (without writing any explicit definitions) should always correspond to common default usage and common presumptions. And only in case anybody needs something special (like "preloading" 10 ids at one time) he should WRITE SOMETHING, write any additional explicit definitions.

        Thus, is there any possibility to change the default value of $definition['allocationSize'] in Doctrine/ORM/Mapping/ClassMetaFactory.php from 10 to 1, or at least make it configurable in doctrine config?

        If so, you will avoid many problems and many confusions from many further Doctrine users.

        Show
        Jan Tichý added a comment - - edited Hi Roman, current default value for allocationSize=10 is CONFUSING and may (and surely WILL) cause problems and misunderstoods for many people in future. The core of the problem is that we define table structure manually, separately from entity annotations. Many people do that. And while the default allocationSize is 10, I have to remember each time I write new table and new entity, that: a) I have to define each the sequence in database manually with INCREMENT BY 10 b) OR I have to define in each entity manually the annotation for @SequenceGenerator - allocationSize=1 c) OR I have to manually use strategy="IDENTITY", but according to documentation it is NOT supported by PostgreSQL Shortly, I have to remember and explicitly WRITE SOMETHING as to avoid problems caused by wrong default value and to get myself to common default (increment by 1) considered by common meaning I think that default value (without writing any explicit definitions) should always correspond to common default usage and common presumptions. And only in case anybody needs something special (like "preloading" 10 ids at one time) he should WRITE SOMETHING, write any additional explicit definitions. Thus, is there any possibility to change the default value of $definition ['allocationSize'] in Doctrine/ORM/Mapping/ClassMetaFactory.php from 10 to 1, or at least make it configurable in doctrine config? If so, you will avoid many problems and many confusions from many further Doctrine users.
        Hide
        Roman S. Borschel added a comment -

        I updated the documentation: http://www.doctrine-project.org/documentation/manual/2_0/en/basic-mapping#identifiers-/-primary-keys:identifier-generation-strategies

        If you still think the allocationSize should default to 1, even for "real" sequences (not SERIAL), please open a new enhancement request.

        Thanks for your suggestions.

        Show
        Roman S. Borschel added a comment - I updated the documentation: http://www.doctrine-project.org/documentation/manual/2_0/en/basic-mapping#identifiers-/-primary-keys:identifier-generation-strategies If you still think the allocationSize should default to 1, even for "real" sequences (not SERIAL), please open a new enhancement request. Thanks for your suggestions.
        Hide
        Jan Tichý added a comment -

        Roman, thank you.

        The new request opened, see http://www.doctrine-project.org/jira/browse/DDC-577.

        I think this issue can be closed.

        Show
        Jan Tichý added a comment - Roman, thank you. The new request opened, see http://www.doctrine-project.org/jira/browse/DDC-577 . I think this issue can be closed.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Václav Novotný
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: