DDC-2905: MySQL MyISAM Engine / Transaction rollback does not work #3620

Closed
opened 2026-01-22 14:23:50 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 11, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jack88:

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)

 
Originally created by @doctrinebot on GitHub (Jan 11, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jack88: 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; <ins>----</ins>----------<ins> | id | name | </ins>----<ins>----------</ins> | 1 | Mr. Test | <ins>----</ins>----------+ mysql> select \* from addresses; Empty set (0.00 sec) ```   ```
admin added the Bug label 2026-01-22 14:23:50 +01:00
admin closed this issue 2026-01-22 14:23:56 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 11, 2014):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Jan 11, 2014): Comment created by @beberlei: This is not an issue with Doctrine, MyISAM does not support rollbacks. Use InnoDB instead.
Author
Owner

@doctrinebot commented on GitHub (Jan 11, 2014):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jan 11, 2014): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3620