You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Laird Nelson <lj...@gmail.com> on 2011/10/25 19:31:49 UTC

EntityManager#createNamedQuery(String, Class) problem

We're using OpenJPA 2.1.0.

I've got a case where I'm building a query like this:

TypedQuery<SomeInterface> q = em.createNamedQuery("someQuery",
SomeInterface.class);

Now, SomeInterface is not the actual entity class--that would be
SomeInterfaceEntity (not mentioned above, as you'll note).  But it is an
interface that the results of the query all implement.

EclipseLink and Hibernate both accept this declaration just fine and run the
associated query just fine.

At runtime, this version of OpenJPA seems to be trying to treat
SomeInterface.class as though it denoted an entity:

<openjpa-2.0.0-beta3-r422266:926797 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Result type "interface
com.foobar.SomeInterface" does not have any public fields or setter methods
for the projection or aggregate result element "SomeInterfaceEntity", nor
does it have a generic put(Object,Object) method that can be used, nor does
it have a public constructor that takes the types null.
    at org.apache.openjpa.kernel.ResultPacker.<init>(ResultPacker.java:158)
    at org.apache.openjpa.kernel.ResultPacker.<init>(ResultPacker.java:103)
    at
org.apache.openjpa.kernel.QueryImpl.getResultPacker(QueryImpl.java:1289)
    at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1228)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
    at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
    at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
    at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)

Truth be told, I have no idea what OpenJPA is trying to tell me here.

JPA's Javadoc places no restrictions on the class passed in as the second
argument to EntityManager#createNamedQuery(String,
Class)<http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#createNamedQuery%28java.lang.String,%20java.lang.Class%29>.
The JPA specification doesn't do so either, at least in the sections I read
concerning queries.

I am also using (I know, I know) subclass-based enhancement.

What...are my options here?

Best,
Laird

-- 
http://about.me/lairdnelson

Re: EntityManager#createNamedQuery(String, Class) problem

Posted by Rick Curtis <cu...@gmail.com>.
> I am also using (I know, I know) subclass-based enhancement.
Have you tried with build time, or -javaagent enhancement?

Can you put together a small unit test?

Thanks,
Rick

On Tue, Oct 25, 2011 at 12:31 PM, Laird Nelson <lj...@gmail.com> wrote:

> We're using OpenJPA 2.1.0.
>
> I've got a case where I'm building a query like this:
>
> TypedQuery<SomeInterface> q = em.createNamedQuery("someQuery",
> SomeInterface.class);
>
> Now, SomeInterface is not the actual entity class--that would be
> SomeInterfaceEntity (not mentioned above, as you'll note).  But it is an
> interface that the results of the query all implement.
>
> EclipseLink and Hibernate both accept this declaration just fine and run
> the
> associated query just fine.
>
> At runtime, this version of OpenJPA seems to be trying to treat
> SomeInterface.class as though it denoted an entity:
>
> <openjpa-2.0.0-beta3-r422266:926797 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: Result type "interface
> com.foobar.SomeInterface" does not have any public fields or setter methods
> for the projection or aggregate result element "SomeInterfaceEntity", nor
> does it have a generic put(Object,Object) method that can be used, nor does
> it have a public constructor that takes the types null.
>    at org.apache.openjpa.kernel.ResultPacker.<init>(ResultPacker.java:158)
>    at org.apache.openjpa.kernel.ResultPacker.<init>(ResultPacker.java:103)
>    at
> org.apache.openjpa.kernel.QueryImpl.getResultPacker(QueryImpl.java:1289)
>    at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1228)
>    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
>    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
>    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
>    at
> org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
>    at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
>    at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
>
> Truth be told, I have no idea what OpenJPA is trying to tell me here.
>
> JPA's Javadoc places no restrictions on the class passed in as the second
> argument to EntityManager#createNamedQuery(String,
> Class)<
> http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#createNamedQuery%28java.lang.String,%20java.lang.Class%29
> >.
> The JPA specification doesn't do so either, at least in the sections I read
> concerning queries.
>
> I am also using (I know, I know) subclass-based enhancement.
>
> What...are my options here?
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>



-- 
*Rick Curtis*

Re: EntityManager#createNamedQuery(String, Class) problem

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, Oct 25, 2011 at 1:31 PM, Laird Nelson <lj...@gmail.com> wrote:

> I've got a case where I'm building a query like this:
>
> TypedQuery<SomeInterface> q = em.createNamedQuery("someQuery",
> SomeInterface.class);
>
> Now, SomeInterface is not the actual entity class--that would be
> SomeInterfaceEntity (not mentioned above, as you'll note).  But it is an
> interface that the results of the query all implement.
>
> EclipseLink and Hibernate both accept this declaration just fine and run
> the associated query just fine.
>
> At runtime, this version of OpenJPA seems to be trying to treat
> SomeInterface.class as though it denoted an entity:
>
> <openjpa-2.0.0-beta3-r422266:926797 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: Result type "interface
> com.foobar.SomeInterface" does not have any public fields or setter methods
> for the projection or aggregate result element "SomeInterfaceEntity", nor
> does it have a generic put(Object,Object) method that can be used, nor does
> it have a public constructor that takes the types null.
>

I've filed https://issues.apache.org/jira/browse/OPENJPA-2065 to track
this.  Has anyone else run into this issue?

Best,
Laird

-- 
http://about.me/lairdnelson