[
https://issues.apache.org/jira/browse/OPENJPA-2484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13945197#comment-13945197
]
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 query
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: https://issues.apache.org/jira/browse/OPENJPA-2484
> 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 u.id = :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 u.id = :id").setParameter("id", user.getId())
> .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 u.id = :id"
> at
> org.apache.openjpa.kernel.ExpressionStoreQuery$AbstractExpressionExecutor.assertNotContainer(ExpressionStoreQuery.java:328)
> at
> org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.<init>(ExpressionStoreQuery.java:770)
> at
> org.apache.openjpa.kernel.ExpressionStoreQuery.newDataStoreExecutor(ExpressionStoreQuery.java:179)
> at
> org.apache.openjpa.kernel.QueryImpl.createExecutor(QueryImpl.java:749)
> at
> org.apache.openjpa.kernel.QueryImpl.compileForDataStore(QueryImpl.java:707)
> at
> org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:689)
> at org.apache.openjpa.kernel.QueryImpl.compile(QueryImpl.java:589)
> at
> org.apache.openjpa.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:997)
> at
> org.apache.openjpa.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:979)
> at
> org.apache.openjpa.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:102)
> at
> org.example.domain.OpenJpaPlainJpaTests.foo(OpenJpaPlainJpaTests.java:301)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> {code}
> Other JPA implementations like Hibernate or EclipseLink support this.
--
This message was sent by Atlassian JIRA
(v6.2#6252)