OpenJPA
  1. OpenJPA
  2. OPENJPA-1043

JPQL queries do not support queries on a MappedSuperclass

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1, 1.3.0, 2.0.0-M2
    • Fix Version/s: 2.0.0-M3
    • Component/s: jpa
    • Labels:
      None

      Description

      This issue was reported by Jim Weaver via a nabble user forum post[1]. The JPA specification clearly states that queries upon a mapped superclass are not permitted, but the OpenJPA documentation has a note saying that they are supported[2].

      Given:
      @MappedSuperclass class A { }
      @Entity class B extends A { }
      @Entity class C extends A { }

      I found that:

      a) The em.find(A.class, id) operation does indeed allow the use of mapped superclass. OpenJPA issues a select upon tables B and C looking for a matching ID.
      b) A JPQL query does not: SELECT a FROM A a fails with exception: (as reported by Jim)

      I receive error message "An error occurred while parsing the query filter
      "SELECT a FROM A a". Error message: The name "A" is not a recognized
      entity or identifier. Perhaps you meant B, which is a close match. Known
      entity names: [B, C]"

      I attempted the same test with the OpenJPA base 1.0 provider and it failed with the same error so it doesn't look like this was ever supported via. JPQL.

      If the decision is made not to provide this support in the near future, the documentation should be updated to qualify that mapped superclass is only allow on a find.

      [1] http://n2.nabble.com/Can%27t-query-against-a-MappedSuperclass-tp2665700p2665700.html
      [2] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#jpa_overview_meta_embeddablesuper

      1. openJPATestcase.zip
        12 kB
        Ravi P Palacherla

        Issue Links

          Activity

          Hide
          Ravi P Palacherla added a comment -

          OpenJPA testcase where I can query against mappedsuperclass.

          Show
          Ravi P Palacherla added a comment - OpenJPA testcase where I can query against mappedsuperclass.
          Hide
          Ravi P Palacherla added a comment -

          Hi,

          In case it is helpful, when I give the complete packagename of the mappedsuperclass in the query then I am not seeing this issue.

          E.g:
          Query newQuery = pm.createQuery("select x from test.kodo.memofield.AbstractInstance x");
          List l = newQuery.getResultList();

          Attached " openJPATestcase.zip" is the test case that will not break and the query is against mappessuperclass (with complete packagename).

          To run the test case:

          1) ant
          2) ant test.

          The version that I tested it against:

          java org.apache.openjpa.conf.OpenJPAVersion

          OpenJPA 2.0.0-SNAPSHOT
          version id: openjpa-2.0.0-SNAPSHOT-r422266:753596
          Apache svn revision: 422266:753596

          Regards,
          Ravi.

          Show
          Ravi P Palacherla added a comment - Hi, In case it is helpful, when I give the complete packagename of the mappedsuperclass in the query then I am not seeing this issue. E.g: Query newQuery = pm.createQuery("select x from test.kodo.memofield.AbstractInstance x"); List l = newQuery.getResultList(); Attached " openJPATestcase.zip" is the test case that will not break and the query is against mappessuperclass (with complete packagename). To run the test case: 1) ant 2) ant test. The version that I tested it against: java org.apache.openjpa.conf.OpenJPAVersion OpenJPA 2.0.0-SNAPSHOT version id: openjpa-2.0.0-SNAPSHOT-r422266:753596 Apache svn revision: 422266:753596 Regards, Ravi.
          Hide
          Pinaki Poddar added a comment -
          Show
          Pinaki Poddar added a comment - See OPENJPA-1049

            People

            • Assignee:
              Pinaki Poddar
              Reporter:
              Jeremy Bauer
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development