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

Closed
opened 2026-01-22 13:05:49 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 30, 2010).

Originally assigned to: @beberlei on GitHub.

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 = ?

Originally created by @doctrinebot on GitHub (Dec 30, 2010). Originally assigned to: @beberlei on GitHub. 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 = ?
admin added the Bug label 2026-01-22 13:05:49 +01:00
admin closed this issue 2026-01-22 13:05:50 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 30, 2010):

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 commented on GitHub (Dec 30, 2010): 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 ;-)
Author
Owner

@doctrinebot commented on GitHub (Jan 4, 2011):

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 commented on GitHub (Jan 4, 2011): 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. ``` php 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; } } ```
Author
Owner

@doctrinebot commented on GitHub (Jan 23, 2011):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Jan 23, 2011): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Jan 23, 2011):

Issue was closed with resolution "Fixed"

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

No dependencies set.

Reference: doctrine/archived-orm#1200