glassfish
  1. glassfish
  2. GLASSFISH-20795

EclipseLink 2.5.0 JPQL Parser breaks column alias handling in ORDER BY clause

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: 4.0
    • Fix Version/s: None
    • Component/s: jdbc
    • Labels:
      None
    • Environment:

      Glassfish 4 (b89), EclipseLink 2.5.0 (included)

      Description

      Column alias (result_variable) handling as defined in JPA Spec 2.1 (JSR-338) "4.9 ORDER BY Clause" is not working with the default EclipseLink 2.5.0 JPQL Parser (Hermes) provided in Glassfish 4.0 (b89). If a basic JPQL query contains two column aliases and there is an ORDER BY clause on the first alias, EclipseLink returns the following exception:

      Exception Description: Problem compiling [SELECT c.cuNumber, c.nameLast AS last_name, c.nameFirst AS first_name FROM Customer c ORDER BY last_name].
      [70, 79] The identification variable 'last_name' is not defined in the FROM clause.

      Example:
      ========
      Create an entity 'Customer' similar to:

      @Entity
      @Access(AccessType.FIELD)
      @Table(name = "CUSTOMER")
      public class Customer implements Serializable {

      ...
      @Column(name = "CU_NUMBER")
      private String cuNumber;
      @Column(name = "HY_NAME_LAST")
      private String nameLast;
      @Column(name = "HY_NAME_FIRST")
      private String nameFirst;
      ...
      }

      In a SLSB use:

      ...
      @PersistenceContext(unitName = "TEST_PU")
      EntityManager em;
      ...

      Query query = em.createQuery("SELECT c.cuNumber, c.nameLast AS last_name, c.nameFirst AS first_name FROM Customer c ORDER BY last_name");
      ...

      This fails with:
      Exception Description: Problem compiling [SELECT c.cuNumber, c.nameLast AS last_name, c.nameFirst AS first_name FROM Customer c ORDER BY last_name].
      [70, 79] The identification variable 'last_name' is not defined in the FROM clause.

      If you use the second alias in the order by clause the query is executed successfully.
      The same query is running without any error in Glassfish 3.1.2.2 using supplied EclipseLink version.

      It seems to be a EclipseLink JPQL Parser Bug.
      As a workaround you can switch back to the prior EclipseLink 2.4 JPQL Parser by using the following configuration in your persistence.xml:
      <property name="eclipselink.jpql.parser" value="org.eclipse.persistence.queries.ANTLRQueryBuilder"/>
      But I don't think the old JPQL parser is JEE 7 compliant.

        Activity

        Hide
        dimaki added a comment -
        Show
        dimaki added a comment - See also here: http://www.eclipse.org/forums/index.php/t/489531/
        Hide
        PascalFilion added a comment -

        The bug has been fixed and will be part of the next patch release (2.4.3 and 2.5.1). A nightly build can be picked up if required.
        https://bugs.eclipse.org/bugs/show_bug.cgi?id=410808

        Show
        PascalFilion added a comment - The bug has been fixed and will be part of the next patch release (2.4.3 and 2.5.1). A nightly build can be picked up if required. https://bugs.eclipse.org/bugs/show_bug.cgi?id=410808

          People

          • Assignee:
            sfelts
            Reporter:
            dimaki
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: