OpenJPA
  1. OpenJPA
  2. OPENJPA-2065

JPA 2.0 Spec. Violation? EntityManager#createNamedQuery(String, Class) bombs with non-entity Class parameter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0, 2.1.1, 2.2.0
    • Fix Version/s: 2.2.0
    • Component/s: jpa
    • Labels:

      Description

      Suppose we have an interface, A.

      Suppose we have a JPA-compliant entity class, B, that implements A.

      This construction will fail at runtime:

      final TypedQuery<A> q = em.createNamedQuery("someNamedQuery", A.class);

      Hibernate and EclipseLink both accept this construction.

      I don't see anywhere in the JPA specification that the class parameter must denote an entity type.

        Issue Links

          Activity

          Hide
          Albert Lee added a comment -

          Close issue in preparation for 2.2.0 release.

          Show
          Albert Lee added a comment - Close issue in preparation for 2.2.0 release.
          Hide
          Rick Curtis added a comment -

          Pinaki committed a code fix, and I committed a unit test. Marking issue as resolved.

          Show
          Rick Curtis added a comment - Pinaki committed a code fix, and I committed a unit test. Marking issue as resolved.
          Hide
          Rick Curtis added a comment -

          Updating fix/affects version.

          Show
          Rick Curtis added a comment - Updating fix/affects version.
          Hide
          Laird Nelson added a comment -

          Sure; not trying to be difficult. Thanks for the quick response, and the pointers to 2.11.3. I'm guessing that this section (2.11.3) was created before there was a TypedQuery-returning method on EntityManager, and that the spec. authors would probably modify it if it were brought to their attention.

          Show
          Laird Nelson added a comment - Sure; not trying to be difficult. Thanks for the quick response, and the pointers to 2.11.3. I'm guessing that this section (2.11.3) was created before there was a TypedQuery-returning method on EntityManager, and that the spec. authors would probably modify it if it were brought to their attention.
          Hide
          Kevin Sutter added a comment -

          Fair enough, Laird. I didn't say it wasn't a valid request. I was just looking for a "get out of jail free" card for the spec violation statement... Thanks again for bringing this to our attention.

          Show
          Kevin Sutter added a comment - Fair enough, Laird. I didn't say it wasn't a valid request. I was just looking for a "get out of jail free" card for the spec violation statement... Thanks again for bringing this to our attention.
          Hide
          Laird Nelson added a comment -

          That would imply among other things that this too is illegal:

          final TypedQuery<Long> q = em.createNamedQuery("someQueryThatReturnsAnAggregateOrCOUNTResult", Long.class);

          And this:

          final TypedQuery<Object[]> q = em.createNamedQuery("someQueryThatReturnsAnObjectArrayBecauseOfStuffInTheSelectClause", Object[].class);

          Is that really the case? Section 2.11 has very narrow scope. 2.11.3 would seem to have been conceived of within the bounds of that scope, not within the bounds of the entire specification. Nevertheless, there it is. That is really unfortunate. I'll ask the sleepy users@jpa-spec.java.net list, where I appear to be the only poster, what they think.

          Show
          Laird Nelson added a comment - That would imply among other things that this too is illegal: final TypedQuery<Long> q = em.createNamedQuery("someQueryThatReturnsAnAggregateOrCOUNTResult", Long.class); And this: final TypedQuery<Object[]> q = em.createNamedQuery("someQueryThatReturnsAnObjectArrayBecauseOfStuffInTheSelectClause", Object[].class); Is that really the case? Section 2.11 has very narrow scope. 2.11.3 would seem to have been conceived of within the bounds of that scope, not within the bounds of the entire specification. Nevertheless, there it is. That is really unfortunate. I'll ask the sleepy users@jpa-spec.java.net list, where I appear to be the only poster, what they think.
          Hide
          Kevin Sutter added a comment -

          Laird,
          This does look to be a valid request, but I don't think it's a spec compliance issue. According to section 2.11.3, non-entity classes (interfaces) can not be passed as arguments to EM and Query methods:

          "Non-entity classes cannot be passed as arguments to methods of the EntityManager or Query
          interfaces[24] and cannot bear mapping information."

          An easy work around for now is to not utilize the TypedQuery support and cast the results instead. Not great, but it's workable until a better solution is developed.

          BTW, having both EclipseLink and Hibernate support this does add to the weight of resolving this JIRA...

          Thanks,
          Kevin

          Show
          Kevin Sutter added a comment - Laird, This does look to be a valid request, but I don't think it's a spec compliance issue. According to section 2.11.3, non-entity classes (interfaces) can not be passed as arguments to EM and Query methods: "Non-entity classes cannot be passed as arguments to methods of the EntityManager or Query interfaces [24] and cannot bear mapping information." An easy work around for now is to not utilize the TypedQuery support and cast the results instead. Not great, but it's workable until a better solution is developed. BTW, having both EclipseLink and Hibernate support this does add to the weight of resolving this JIRA... Thanks, Kevin

            People

            • Assignee:
              Rick Curtis
              Reporter:
              Laird Nelson
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development