Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1456

Sequence doesn't work correctly when sequence is defined second in a composite key

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Oracle

      Description

      When using a sequence in Oracle as part of a composite key and the sequence is defined second, Doctrine retrieves from the sequence correctly but incorrectly assigns to the first key (which in this case is not the correct column)

      Example:

      /Entity/ItemModel.php
      /**
       * @Column(name="submission_id", type="integer")
       * @Id
       */
      private $submissionId;
      
      /**
       * @Column(name="model_id", type="integer")
       * @Id
       * @GeneratedValue(strategy="AUTO")
       * @SequenceGenerator(sequenceName="model_id_seq", initialValue=1, allocationSize=1)
       */
      private $modelId;
      

      Doctrine correctly retrieves the sequence, however it then attempts to set the first identifier field (in this case submission_id) instead of the sequence key.

      The problem appears in /Doctrine/ORM/UnitOfWork.php line 613.
      $class->indentifier is hard coded to item 0.

      $this->entityIdentifiers[$oid] = array($class->identifier[0] => $idValue);
      

      You can workaround this issue by defining the sequence first in the entity.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This is not allowed currently, there is a PR for custom id generators, but so long i am closing this as invalid.

        Also i added an error exception which makes this kind of setup fail.

        Show
        Benjamin Eberlei added a comment - This is not allowed currently, there is a PR for custom id generators, but so long i am closing this as invalid. Also i added an error exception which makes this kind of setup fail.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Chris Colborne
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: