| Summary: | NullPointerException in CriteriaQueryImpl when using multiselect | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Lucas Persson <lucas> | ||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | major | ||||||
| Priority: | P2 | CC: | david.minsky, tom.ware | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Linux | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines Community: Please vote for this bug if it is important to you. Votes are one of the main criteria we use to determine which bugs to fix next. Reproduced with the following test code:
public void testTupleQuery() {
EntityManager em = createEntityManager();
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = qb.createTupleQuery();
Root<Employee> emp = criteria.from(Employee.class);
Path exp = emp.get("lastName");
criteria.multiselect(exp, qb.count(exp));
criteria.where(qb.conjunction());
criteria.groupBy(exp);
TypedQuery<Tuple> query = em.createQuery(criteria);
List<Tuple> list = query.getResultList();
}
Stacktrace:
java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.createCompoundQuery(CriteriaQueryImpl.java:543)
at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.translate(CriteriaQueryImpl.java:715)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1412)
at org.eclipse.persistence.testing.tests.jpa.criteria.JUnitCriteriaSimpleTestSuite.testTupleQuery(JUnitCriteriaSimpleTestSuite.java:2852)
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 junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at org.eclipse.persistence.testing.framework.junit.JUnitTestCase.runBare(JUnitTestCase.java:551)
Created attachment 201525 [details]
Proposed patch
Fixed in trunk (2.4) at revision: 9900 Fixed in 2.3 branch (2.3.1) at revision: 9902 Fixed in 2.2 branch at revision: 9905 Fixed in 2.1 branch at revision: 9906 The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
Hi I get a NullPointerException when caling EntityManager.createQuery(criteria) at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryI mpl.createCompoundQuery(CriteriaQueryImpl.java:543) (I am using EclipseLink 2.1.2.v20101206-r8635 from within Weblogic 10.3.4, I have also tried EclipseLink 2.3.0.v20110202-r8914) Here is the code: public List<Tuple> getTopUsage( int lenght) { CriteriaBuilder builder = mEntityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); SingularAttribute<Cdr, String> attribute = Cdr_.callingParty; Root<Cdr> cdr = criteria.from(Cdr.class); criteria.multiselect(cdr.get(attribute), builder.count(cdr.get(attribute))); criteria.where(builder.conjunction()); criteria.groupBy(cdr.get(attribute)); TypedQuery<Tuple> query = mEntityManager.createQuery(criteria); query.setMaxResults(lenght); List<Tuple> list = query.getResultList(); return list; } Checking the code in EclipseLink then it (createCompoundQuery) assumes that the criteriaQuery's where member always has a "current node" and that is not the case with a predicate like the one I can get from the builder like this: builder.conjunction(). (in my real code I pass in some parameters to build up the 'where' clause) Here is the stacktrace. java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryI mpl.createCompoundQuery(CriteriaQueryImpl.java:543) at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryI mpl.translate(CriteriaQueryImpl.java:715) at org.eclipse.persistence.internal.jpa.EntityManagerImpl.creat eQuery(EntityManagerImpl.java:1313) at sun.reflect.GeneratedMethodAccessor168.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at weblogic.persistence.QueryProxyImpl.instantiateQuery(QueryPr oxyImpl.java:56) at weblogic.persistence.QueryProxyImpl.createQuery(QueryProxyIm pl.java:74) at weblogic.persistence.QueryProxyImpl.getResultList(QueryProxy Impl.java:145) at xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.CdrBeanImpl.getTopUsage(CdrBea nImpl.java:230) Thanks Lucas