openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Sutter (JIRA)" <>
Subject [jira] [Commented] (OPENJPA-2484) JPA-QL query with byte[] projection fails.
Date Mon, 24 Mar 2014 15:07:42 GMT


Kevin Sutter commented on OPENJPA-2484:

Fine line on interpretation of the spec...  According to section 4.8 of the JPA 2.0 spec,
only single-valued expressions can be specified in the SELECT clause:

"Note that the SELECT clause must be specified to return only single-valued expressions. The
below is therefore not valid:

SELECT o.lineItems FROM Order AS o"

But, in this particular case, you are not trying to access a collection that is the result
of a *ToMany relationship.  You are just trying to access an attribute of this Entity, which
happens to be an array of bytes...  Unfortunately, the above spec item is getting in your
way...  I'm tending to agree that this situation should be allowed.  I have no idea on the
impact or work required, so let's leave that out of the equation at this point.  What do others
think?  Is this request within or outside of the spirit of the spec?

> JPA-QL query with byte[] projection fails.
> ------------------------------------------
>                 Key: OPENJPA-2484
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.2.2
>            Reporter: Thomas Darimont
> Given a User entity with a persistent byte[] field declared as:
> @Lob private byte[] binaryData;
> When executing the following JPA query:
> select u.binaryData from User u where = :id
> {code:java}
> 	User user = new User();
> 		user.setBinaryData("TEST".getBytes());
> 		em.persist(user);
> 		Object result = em.createQuery("select u.binaryData from User u where = :id").setParameter("id",
> 				.getSingleResult();
>                 assertThat(result,is(notNullValue()));
> {code}
> The following exception is thrown:
> {code}
> <openjpa-2.3.0-r422266:1540826 nonfatal user error> org.apache.openjpa.persistence.ArgumentException:
Query projections cannot include array, collection, or map fields.  Invalid query: "select
u.binaryData from User u where = :id"
> 	at org.apache.openjpa.kernel.ExpressionStoreQuery$AbstractExpressionExecutor.assertNotContainer(
> 	at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.<init>(
> 	at org.apache.openjpa.kernel.ExpressionStoreQuery.newDataStoreExecutor(
> 	at org.apache.openjpa.kernel.QueryImpl.createExecutor(
> 	at org.apache.openjpa.kernel.QueryImpl.compileForDataStore(
> 	at org.apache.openjpa.kernel.QueryImpl.compileForExecutor(
> 	at org.apache.openjpa.kernel.QueryImpl.compile(
> 	at org.apache.openjpa.persistence.EntityManagerImpl.createQuery(
> 	at org.apache.openjpa.persistence.EntityManagerImpl.createQuery(
> 	at org.apache.openjpa.persistence.EntityManagerImpl.createQuery(
> 	at
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
> 	at java.lang.reflect.Method.invoke(
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> 	at
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(
> 	at org.junit.runners.ParentRunner.runLeaf(
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
> 	at org.junit.runners.ParentRunner$
> 	at org.junit.runners.ParentRunner$1.schedule(
> 	at org.junit.runners.ParentRunner.runChildren(
> 	at org.junit.runners.ParentRunner.access$000(
> 	at org.junit.runners.ParentRunner$2.evaluate(
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(
> 	at
> 	at
> 	at
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
> 	at
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> {code}
> Other JPA implementations like Hibernate or EclipseLink support this.

This message was sent by Atlassian JIRA

View raw message