Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-841

Generated SQL contains non-existen alias

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-RC1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Result:

      PDOException: SQLSTATE[HY000]: General error: 1 no such column: e2_.owner_id

      Generated SQL:

      SELECT c0_.id AS id0, c0_.createdAt AS createdAt1, c0_.updatedAt AS updatedAt2, c0_.title AS title3, c0_.color AS color4, c0_.owner_id AS owner_id5 FROM calendar c0_ INNER JOIN user u1_ ON e2_.owner_id = u1_.id WHERE u1_.username = 'bot'

      Notice how the table alias "e2" does not existm yet is used in the join clause.

      Meta:

      /**

      • @ManyToOne(targetEntity="User")
      • @JoinColumn(name="owner_id", referencedColumnName="id")
        *
      • @var User
        */

      DQL:

      SELECT c FROM Calendar c JOIN c.owner u WHERE u.username = 'bot'

      A workaround would be appreciated.

      Thanks!

        Issue Links

          Activity

          John Kleijn created issue -
          Hide
          John Kleijn added a comment -

          This also happened with BETA1 and also in other scenarios, e.g.

          SELECT w0_.id AS id0, w0_.createdAt AS createdAt1, w0_.updatedAt AS updatedAt2, w0_.start AS start3, w0_.end AS end4, w0_.owner_id AS owner_id5 FROM worklog w0_ INNER JOIN user u1_ ON e2_.owner_id = u1_.id WHERE u1_.id = ? AND w0_.start IS NULL

          SQLSTATE[HY000]: General error: 1 no such column: e2_.owner_id

          This may have to do with the "owner" field being defined in a mapped superclass.

          Show
          John Kleijn added a comment - This also happened with BETA1 and also in other scenarios, e.g. SELECT w0_.id AS id0, w0_.createdAt AS createdAt1, w0_.updatedAt AS updatedAt2, w0_.start AS start3, w0_.end AS end4, w0_.owner_id AS owner_id5 FROM worklog w0_ INNER JOIN user u1_ ON e2_.owner_id = u1_.id WHERE u1_.id = ? AND w0_.start IS NULL SQLSTATE [HY000] : General error: 1 no such column: e2_.owner_id This may have to do with the "owner" field being defined in a mapped superclass.
          Hide
          John Kleijn added a comment -

          Confirmed, when I move the declaration down to the implementation class the exception goes away.

          When I add it rather then moving it, I get an exception saying the field was already added, so the declaration in the supertype is not simply omitted (not that that would explain the invalid SQL).

          Show
          John Kleijn added a comment - Confirmed, when I move the declaration down to the implementation class the exception goes away. When I add it rather then moving it, I get an exception saying the field was already added, so the declaration in the supertype is not simply omitted (not that that would explain the invalid SQL).
          Hide
          Roman S. Borschel added a comment - - edited

          Generall,y mapped superclasses may only define unidirectional associations, because an association can not point back to a mapped superclass (a mapped superclass is not a persistent class). The relevant doc section is here: http://www.doctrine-project.org/projects/orm/2.0/docs/reference/inheritance-mapping/en#mapped-superclasses

          Though, in your example the association actually points back to an entity, not the mapped superclass, so this may be a case that can be addressed properly, so we need to investigate this further.

          ps: It is not entirely clear from the information you provided, but I assume there is no class that has targetEntity="NameOfMappedSuperclass" ? Because that will by definition never work.

          Show
          Roman S. Borschel added a comment - - edited Generall,y mapped superclasses may only define unidirectional associations, because an association can not point back to a mapped superclass (a mapped superclass is not a persistent class). The relevant doc section is here: http://www.doctrine-project.org/projects/orm/2.0/docs/reference/inheritance-mapping/en#mapped-superclasses Though, in your example the association actually points back to an entity, not the mapped superclass, so this may be a case that can be addressed properly, so we need to investigate this further. ps: It is not entirely clear from the information you provided, but I assume there is no class that has targetEntity="NameOfMappedSuperclass" ? Because that will by definition never work.
          Hide
          John Kleijn added a comment -

          No, there are no associations to the mapped superclass.

          It is purely for defining common meta data and properties for a certain type, exactly what one would use a mapped superclass for.

          It's worth noting that while this is a birectional association between the two types when viewed statically, we're not talking about a single, bidirectional relation:

          • Calendar has an owner, which is a User. This is the user that created the object, a mechanism applicable to most entities in the system, hence the mapped superclass.
          • A User has a Calendar, but he may or may not be the "owner" of that Calendar.

          So User has this specified:

          /**

          • @ManyToOne(targetEntity=Calendar", fetch="EAGER", cascade= {"persist", "remove"}

            )

          • @JoinColumn(name="calendar_id", referencedColumnName="id")
            *
          • @var Calendar
            */
            private $calendar;
          Show
          John Kleijn added a comment - No, there are no associations to the mapped superclass. It is purely for defining common meta data and properties for a certain type, exactly what one would use a mapped superclass for. It's worth noting that while this is a birectional association between the two types when viewed statically, we're not talking about a single, bidirectional relation: Calendar has an owner, which is a User. This is the user that created the object, a mechanism applicable to most entities in the system, hence the mapped superclass. A User has a Calendar, but he may or may not be the "owner" of that Calendar. So User has this specified: /** @ManyToOne(targetEntity=Calendar", fetch="EAGER", cascade= {"persist", "remove"} ) @JoinColumn(name="calendar_id", referencedColumnName="id") * @var Calendar */ private $calendar;
          Hide
          John Kleijn added a comment -

          Obviously this means that a User also has an "owner", which may or may not be the object itself.

          Show
          John Kleijn added a comment - Obviously this means that a User also has an "owner", which may or may not be the object itself.
          Hide
          Benjamin Eberlei added a comment -

          I think this might be fixed with DDC-671 already.

          Show
          Benjamin Eberlei added a comment - I think this might be fixed with DDC-671 already.
          Roman S. Borschel made changes -
          Field Original Value New Value
          Fix Version/s 2.0-RC1 [ 10091 ]
          Hide
          Benjamin Eberlei added a comment -

          relating

          Show
          Benjamin Eberlei added a comment - relating
          Benjamin Eberlei made changes -
          Link This issue depends on DDC-671 [ DDC-671 ]
          Benjamin Eberlei made changes -
          Link This issue relates to DDC-826 [ DDC-826 ]
          Benjamin Eberlei made changes -
          Link This issue depends on DDC-671 [ DDC-671 ]
          Benjamin Eberlei made changes -
          Link This issue relates to DDC-671 [ DDC-671 ]
          Hide
          Benjamin Eberlei added a comment -

          I need the whole entitiy definitions of Calender and User. Can you please paste them to somewhere?

          Show
          Benjamin Eberlei added a comment - I need the whole entitiy definitions of Calender and User. Can you please paste them to somewhere?
          Benjamin Eberlei made changes -
          Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
          Hide
          Benjamin Eberlei added a comment -

          I cannot reproduce it, i am pretty sure its a duplicate of DDC-671 and should therefore be fixed already in trunk.

          Show
          Benjamin Eberlei added a comment - I cannot reproduce it, i am pretty sure its a duplicate of DDC-671 and should therefore be fixed already in trunk.
          Benjamin Eberlei made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          John Kleijn added a comment -

          > I need the whole entitiy definitions of Calender and User. Can you please paste them to somewhere?

          I have since chaned it, but I emailed you what I think are the relevant revisions of the classes.

          Show
          John Kleijn added a comment - > I need the whole entitiy definitions of Calender and User. Can you please paste them to somewhere? I have since chaned it, but I emailed you what I think are the relevant revisions of the classes.
          John Kleijn made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Benjamin Eberlei made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          John Kleijn added a comment -

          I've had a similar issue with multiple levels of MappedSuperclasses. It works in RC1, fails in 2.0 stable on non-existent table aliases. Don't have time to do a full bug report right now.

          Show
          John Kleijn added a comment - I've had a similar issue with multiple levels of MappedSuperclasses. It works in RC1, fails in 2.0 stable on non-existent table aliases. Don't have time to do a full bug report right now.
          Benjamin Eberlei made changes -
          Link This issue relates to DDC-1013 [ DDC-1013 ]
          Benjamin Eberlei made changes -
          Workflow jira [ 12011 ] jira-feedback [ 14611 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback [ 14611 ] jira-feedback2 [ 16475 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 16475 ] jira-feedback3 [ 18728 ]

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-841, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              John Kleijn
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: