Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

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)

 
@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.