Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2905

MySQL MyISAM Engine / Transaction rollback does not work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: 2.4.1
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
    • Environment:
      debian 6.0.3, MySQL 5.1.49, PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli)

      Description

      I have two simple entities ( user 1:n address)

      <?
      /**
       * @Entity @Table(name="users", options={"engine"="MyISAM"})
       **/
      class User {
          /** @Id @Column(type="integer") @GeneratedValue **/
          protected $id;
          /** @Column(type="string") **/
          protected $name;
      
          /**
           * @OneToMany(targetEntity="Address", mappedBy="user", cascade={"persist"})
           * @var Address[]
           **/
          protected $addresses = null;
      
          public function __construct()
          {
              $this->addresses = new ArrayCollection();
          }
      
          public function getId() {
              return $this->id;
          }
      
          public function setName($name) {
              $this->name = $name;
          }
      
          public function getName() {
              return $this->name;
          }
      
          public function addAddress(Address $address) {
              $this->addresses[] = $address;
              $address->setUser($this);
          }
      }
      
       * @Entity @Table(name="addresses", options={"engine"="MyISAM"})
       **/
      class Address {
          /** @Id @Column(type="integer") @GeneratedValue **/
          protected $id;
          /** @Column(type="string") **/
          protected $zipcode;
          /** @Column(type="string") **/
          protected $city;
      
          /**
           * @ManyToOne(targetEntity="User", inversedBy="addresses")
           * @var User;
           **/
          protected $user = null;
      
          /**
           * @return mixed
           */
          public function getId() {
              return $this->id;
          }
          /**
           * @return mixed
           */
          public function getCity() {
              return $this->city;
          }
      
          /**
           * @param mixed $zipcode
           */
          public function setZipcode($zipcode) {
              $this->zipcode = $zipcode;
          }
      
          /**
           * @return mixed
           */
          public function getZipcode() {
              return $this->zipcode;
          }
      
          public function setUser(User $user) {
              //$user->addAddress($this);
              $this->user = $user;
          }
      
          public function getUser() {
              return $this->user;
          }
      
      }
      
      ?>
      

      When i do this, then i get an exception:

      $user = new User();
      $user->setName('Mr. Test');
      
      $address = new Address();
      $address->setCity('New York');
      
      $user->addAddress($address);
      
      $entityManager->persist($user);
      $entityManager->flush();
      
      
      // Exception:Integrity constraint violation: 1048 Column 'zipcode' cannot be null'
      

      That's okay, but the address-entity needs a zipcode.

      The output from sqlLogger looks like this:

      "START TRANSACTION" INSERT INTO users (name) VALUES (?)
      array
        1 => string 'Mr. Test' (length=5)
      array
        1 => string 'string' (length=6)
      INSERT INTO addresses (zipcode, city, street, user_id) VALUES (?, ?, ?, ?)
      array
        1 => null
        2 => string 'New York' (length=8)
        3 => null
        4 => int 1
      array
        1 => string 'string' (length=6)
        2 => string 'string' (length=6)
        3 => string 'string' (length=6)
        4 => string 'integer' (length=7)
      "ROLLBACK"
      

       

      That Problem is, that the transaction is broken and the rollback operation does not work. I get a new user without a address:

      mysql> select * from users;
      +----+----------+
      | id | name     |
      +----+----------+
      |  1 | Mr. Test |
      +----+----------+
      
      mysql> select * from addresses;
      Empty set (0.00 sec)
      

       

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This is not an issue with Doctrine, MyISAM does not support rollbacks. Use InnoDB instead.

        Show
        Benjamin Eberlei added a comment - This is not an issue with Doctrine, MyISAM does not support rollbacks. Use InnoDB instead.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: