You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by zhourui <zh...@zoneland.net> on 2015/04/27 15:31:50 UTC
how to use orderBy clause in tuple query?
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R
<openjpa-2.2.3-SNAPSHOT-r422266:1595313 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException:
使用过滤器“null”对候选类型“javax.persistence.criteria”执行了此查询,包括将多个查询的结果合并在内存中。您已选择对“”上的结果进行排序,但尚未在
setResult() 子句中选择此数据。请将此排序数据包含在 setResult() 中,以便 OpenJPA 可以抽取此数据以进行内存中排序。
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.getOrderingValue(ExpressionStoreQuery.java:837)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.OrderingMergedResultObjectProvider.getOrderingValue(OrderingMergedResultObjectProvider.java:62)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.lib.rop.MergedResultObjectProvider.next(MergedResultObjectProvider.java:172)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.next(QueryImpl.java:2087)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:35)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1251)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.slice.DistributedQueryImpl.execute(DistributedQueryImpl.java:61)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
[15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
com.ibm.ws.persistence.QueryImpl.getResultList(QueryImpl.java:118)
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<WrapOutCompany> cq = cb.createQuery(WrapOutCompany.class);
Root<Company> root = cq.from(Company.class);
Predicate p = cb.equal(root.get(Company_.level), 1);
cq.multiselect(root.get(Company_.id), root.get(Company_.name),
root.get(Company_.unique), root.get(Company_.level),
root.get(Company_.superior));
cq.where(p);
cq.orderBy(cb.asc(root.get(Company_.name)));
return em.createQuery(cq).getResultList();
use tuple query, where with orderBy clause,it's throw exception,
but without orderBy clause,it's work fine.
how to use orderBy clause in tuple query?
--
View this message in context: http://openjpa.208410.n2.nabble.com/how-to-use-orderBy-clause-in-tuple-query-tp7588024.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: how to use orderBy clause in tuple query?
Posted by Albert Lee <al...@gmail.com>.
The "orderBy" coding looks correct to me.
Looks into the OJ code base, the part where it detects the error seems NOT
be able to
ExpressionStoreQuery {
public Object getOrderingValue(StoreQuery q, Object[] params,
Object resultObject, int orderIndex) {
// if this is a projection, then we have to order on
something <<<<<<< looking for the order path in the selected items
// we selected
if (_exps[0].projections.length > 0) {
String ordering = _exps[0].orderingClauses[orderIndex];
for (int i = 0; i < _exps[0].projectionClauses.length; i++)
if (ordering.equals(_exps[0].projectionClauses[i]))
return ((Object[]) resultObject)[i];
throw new
InvalidStateException(_loc.get <<<<<< but failed
with this expression.
("merged-order-with-result",
q.getContext().getLanguage(),
q.getContext().getQueryString(), ordering));
}
You may want to set a break point here to find out what is in _exps[] and
what are missing that is expected by this method.
Good luck.
Albert.
On Mon, Apr 27, 2015 at 8:31 AM, zhourui <zh...@zoneland.net> wrote:
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R
> <openjpa-2.2.3-SNAPSHOT-r422266:1595313 nonfatal user error>
> org.apache.openjpa.persistence.InvalidStateException:
>
> 使用过滤器“null”对候选类型“javax.persistence.criteria”执行了此查询,包括将多个查询的结果合并在内存中。您已选择对“”上的结果进行排序,但尚未在
> setResult() 子句中选择此数据。请将此排序数据包含在 setResult() 中,以便 OpenJPA 可以抽取此数据以进行内存中排序。
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
>
> org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.getOrderingValue(ExpressionStoreQuery.java:837)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
>
> org.apache.openjpa.kernel.OrderingMergedResultObjectProvider.getOrderingValue(OrderingMergedResultObjectProvider.java:62)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
>
> org.apache.openjpa.lib.rop.MergedResultObjectProvider.next(MergedResultObjectProvider.java:172)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
>
> org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.next(QueryImpl.java:2087)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:35)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1251)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
>
> org.apache.openjpa.slice.DistributedQueryImpl.execute(DistributedQueryImpl.java:61)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
> [15-4-27 21:18:26:952 CST] 000000d7 SystemErr R at
> com.ibm.ws.persistence.QueryImpl.getResultList(QueryImpl.java:118)
>
>
> CriteriaBuilder cb = em.getCriteriaBuilder();
> CriteriaQuery<WrapOutCompany> cq = cb.createQuery(WrapOutCompany.class);
> Root<Company> root = cq.from(Company.class);
> Predicate p = cb.equal(root.get(Company_.level), 1);
> cq.multiselect(root.get(Company_.id), root.get(Company_.name),
> root.get(Company_.unique), root.get(Company_.level),
> root.get(Company_.superior));
> cq.where(p);
> cq.orderBy(cb.asc(root.get(Company_.name)));
> return em.createQuery(cq).getResultList();
>
> use tuple query, where with orderBy clause,it's throw exception,
> but without orderBy clause,it's work fine.
>
> how to use orderBy clause in tuple query?
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/how-to-use-orderBy-clause-in-tuple-query-tp7588024.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
--
Albert Lee.