Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-960

Locking @Version with MappedSuperClass and Single Table Inheritance results in wrong queries

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0.1, 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Windows 7 using Zend Server

      Description

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

        Activity

        Hide
        Benjamin Eberlei added a comment -

        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

        Show
        Benjamin Eberlei added a comment - 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
        Hide
        Jack van Galen added a comment - - edited

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

        Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
         
        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;
        		
        	}
        	
        }
        
        Show
        Jack van Galen added a comment - - edited Oops, my mistake. I meant to say 'class table inheritance'. The definitions that I used (slightly modified and translated to English) are below. Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml 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; } }
        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jack van Galen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: