Skip to content

Loading…

DDC-960: Locking @Version with MappedSuperClass and Single Table Inheritance results in wrong queries #5495

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user jackvangalen:

When using a @version field for locking purposes in one of the fields of a MappedSuperClass, things go wrong. Here is my situation:

SpecificUser extends of BaseUser
There is one mapped superclass containing things like createdOn, createdBy and finally the @version field named version.

Now, when I change a record, the following queries are created. The last one is faulty:

Query: UPDATE specificuser SET firstname = ? WHERE id = ?
Query: UPDATE baseuser SET version = version + 1 WHERE id = ? AND version = ?
Query: SELECT version FROM specificuser WHERE id = ? <======= should be: SELECT version FROM baseuser WHERE id = ?

@doctrinebot

Comment created by @beberlei:

You say Single Table Inheritance but specificuser and baseuser are two different tables? How does that work? With single table inheritance both specificuser and baseuser are in the same table.

Can you post your mappings? I am not convinced of this bug yet ;-)

@doctrinebot

Comment created by jackvangalen:

Oops, my mistake. I meant to say 'class table inheritance'. The definitions that I used (slightly modified and translated to English) are below.

namespace framework{

    /*** @MappedSuperclass **/
    class DbTable {

        /****
         * @Id @Column(type="integer", name="id", length="10", unique="", nullable="")
         * @GeneratedValue(strategy="AUTO")
         */
        private $id;

        /*** @Version @Column(type="integer", name="version", nullable="true") **/
        private $version;

        /*** @Column(type="datetimetz", name="createdon", nullable="true") **/
        private $createdon;

    }

}


namespace custom\tables{

    /****
    * @Entity
    */
    class specificuser extends generated\tables\baseuser {

    }

}


namespace custom\tables{

    /****
     * @Entity
     * @InheritanceType("JOINED")
     * @DiscriminatorColumn(name="discr", type="string")
     * @DiscriminatorMap({"specificuser" = "custom\tables\specificuser"})
     */
    class baseuser extends generated\tables\baseuser {

    }

}


namespace generated\tables{

    class specificuser extends custom\tables\baseuser {
    }

}


namespace generated\tables{

    class user extends framework\DbTable {

        /****
        *@Column(type="string", nullable="false", unique="true")
        */
        protected $username;

    }

}
@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0.1 milestone
@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.