openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pawel Veselov <pawel.vese...@gmail.com>
Subject count() with criteria API - strange (wrong) exception?
Date Thu, 28 Feb 2013 09:15:02 GMT
Hi.

Just to report this weird issue.

OpenJPA version 2.1.1.

    EntityManager em = {magically obtain entity manager}
    CriteriaBuilder cb = ctx.getCriteriaBuilder();
    CriteriaQuery q = cb.createQuery();
    Root<E_Application> root = q.from(E_Application.class);
    Join<E_Application, E_AppState> aStateJoin =
            root.join(E_Application_.publicAppState);
    Join<E_AppState, E_Price> priceJoin =
aStateJoin.join(E_AppState_.prices);

    q.distinct(true);
    q.where(cb.equal(priceJoin.get(E_Price_.currency),
            "something"));
    q.where(cb.equal(aStateJoin.get(E_AppState_.frontState),
            FrontState.PUBLISHED));
    q.orderBy(cb.desc(aStateJoin.get(E_AppState_.executed)));
    TypedQuery<Long> cq =
em.createQuery(q.select(cb.count(root).alias("c")));
    cq.getSingleResult();

Now, I was doing the above to re-use the same query for data retrieval and
counting.
Some exceptions were coming up, so I started experimenting around, and
found what I was doing wrong (q.distinct(true) and q.orderBy() should not
be used), but the exception that I was getting didn't help, and may be an
indication of some other problem. Exception stack trace is below.
Interestingly, removing q.distinct() makes it throw a more reasonable
exception (about .executed not being aggregated)

<openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Failed to execute
query "null". Check the query syntax for correctness. See nested
exception for details.
	org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
	org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
	org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
	org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:315)
	org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:331)
	org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:359)
	org.apache.jsp.appList_jsp._jspService(appList_jsp.java:179)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:927)
	org.apache.jsp.main_jsp._jspService(main_jsp.java:332)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	com.excelfore.snap.SnapStore.service(SnapStore.java:473)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

*root cause*

java.sql.SQLException: org.apache.openjpa.jdbc.kernel.exps.Count@2d2fd7
	org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.findObject(SelectImpl.java:2507)
	org.apache.openjpa.jdbc.sql.ResultSetResult.translate(ResultSetResult.java:497)
	org.apache.openjpa.jdbc.sql.ResultSetResult.getObjectInternal(ResultSetResult.java:362)
	org.apache.openjpa.jdbc.sql.AbstractResult.getObject(AbstractResult.java:691)
	org.apache.openjpa.jdbc.kernel.exps.UnaryOp.load(UnaryOp.java:120)
	org.apache.openjpa.jdbc.kernel.ProjectionResultObjectProvider.getResultObject(ProjectionResultObjectProvider.java:78)
	org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.getResultObject(QueryImpl.java:2075)
	org.apache.openjpa.kernel.QueryImpl.singleResult(QueryImpl.java:1330)
	org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1242)
	org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
	org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
	org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
	org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
	org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:315)
	org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:331)
	org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:359)
	org.apache.jsp.appList_jsp._jspService(appList_jsp.java:179)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:927)
	org.apache.jsp.main_jsp._jspService(main_jsp.java:332)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	com.excelfore.snap.SnapStore.service(SnapStore.java:473)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message