Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 2.2.2
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
      None

      Description

      hello, im new here i dont know if this is the correct place, but try finding help on the web whitout success. so here is my issue.

      im trying to map a one to one relation on 2 entities using the id field on both entities.

      for example:

      i have a customer entity and a cart entity, both entities have only an id field. and there is a FK from cart id to customer id so i make the mappings as follow:

      first the customer:

      Acme\DemoBundle\Entity\Customer:
      type: entity
      table: null
      oneToOne:
      cart:
      targetEntity: Cart
      mappedBy: customer
      fields:
      id:
      type: integer
      id: true
      generator:
      strategy: AUTO
      lifecycleCallbacks: { }

      now the cart:

      Acme\DemoBundle\Entity\Cart:
      type: entity
      table: null
      oneToOne:
      customer:
      targetEntity: Customer
      inversedBy: cart
      joinColumn:
      name: id
      referencedColumnName: id
      fields:
      id:
      type: integer
      id: true

      lifecycleCallbacks: { }

      the entities get generated ok, but im not able to insert in the cart entity:

      im getting the followin exception:

      Entity of type Acme\DemoBundle\Entity\Cart is missing an assigned ID for field 'id'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly.

      when i made the insert a try this two ways:

      $cart = new \Acme\DemoBundle\Entity\Cart();
      $cart->setId($cart->getId());
      $em->persist($cart);
      $em->flush();

      or this one

      $cart = new \Acme\DemoBundle\Entity\Cart();
      $cart->setCustomer($customer);
      $em->persist($cart);
      $em->flush();
      in both cases i get the same exception

      this is the symfony's log where the insert is generated by doctrine to insert the cart record

      [2012-07-16 20:59:06] doctrine.DEBUG: SET NAMES UTF8 ([]) [] []
      [2012-07-16 20:59:06] doctrine.DEBUG: INSERT INTO Customer (id) VALUES (null) ([]) [] []
      [2012-07-16 20:59:06] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException". [] []
      [2012-07-16 20:59:06] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException". [] []
      [2012-07-16 20:59:06] request.CRITICAL: Doctrine\ORM\ORMException: Entity of type Acme\DemoBundle\Entity\Cart is missing an assigned ID for field 'id'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly. (uncaught exception) at /home/javier/intraway/doctrine_test/sf/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 51 [] []

      the only way i get this working is setting the generation strategy to auto but i dont thinks its ok, i want this two entities have the same id and if i make both use generators i cant be surethe ids get generated correctly.

      thanks.

        Activity

        Javier Neyra created issue -
        Alexander made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Javier Neyra
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: