NullPointerException with nested fetch join and multiselect [message #539404] |
Thu, 10 June 2010 15:46 |
Patrice Lachance Messages: 6 Registered: June 2010 |
Junior Member |
|
|
Hi,
I have a JPA 2.0 criteria query that have at least one nested fetch join and a multiselect that throws a NullPointerException. I tested this query on EclipseLink 2.0.0 and 2.0.2. Here's the simplified version of the query :
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> c = cb.createQuery(Object[].class);
Root<Ecole> ec = c.from(Ecole.class);
Fetch<Ecole, Telephone> tel = ec.fetch("telephone", JoinType.INNER);
tel.fetch("lieu", JoinType.INNER);
c.multiselect(ec, ec.get("ecoleNo")).groupBy(ec);
If I comment the line "tel.fetch("lieu", JoinType.INNER);", the query and the nested fetch work.
If I keep the nested fetch and use a simple select instead of a multiselect, the query and the nested fetch work too.
Could it be a bug?
Here's the stack trace :
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.mappings.ForeignReferenceMapping.prepareNestedJoinQueryClone(ForeignReferenceMapping.java:1714)
at org.eclipse.persistence.mappings.OneToOneMapping.valueFromRowInternalWithJoin(OneToOneMapping.java:1533)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java:1532)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.buildCloneFromRow(ForeignReferenceMapping.java:195)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoWorkingCopyClone(ObjectBuilder.java:1261)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneFromRow(ObjectBuilder.java:1388)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:548)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:492)
at org.eclipse.persistence.queries.ReportQueryResult.processItem(ReportQueryResult.java:200)
at org.eclipse.persistence.queries.ReportQueryResult.buildResult(ReportQueryResult.java:140)
at org.eclipse.persistence.queries.ReportQueryResult.<init>(ReportQueryResult.java:75)
at org.eclipse.persistence.queries.ReportQuery.buildObject(ReportQuery.java:591)
at org.eclipse.persistence.queries.ReportQuery.buildObjects(ReportQuery.java:642)
at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:838)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1021)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2898)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:453)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:681)
I need a having clause on an aggegate function but I don't need to get the result of the aggregate function. So, I tried to get rid of the multiselect like this below. It runs but the having clause is ignored.
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Ecole> c = cb.createQuery(Ecole.class);
Root<Ecole> ec = c.from(Ecole.class);
Fetch<Ecole, Telephone> tel = ec.fetch("telephone", JoinType.INNER);
tel.fetch("lieu", JoinType.INNER);
Join<Ecole, EcoleJournee> ej = ec.join("ecoleJourneeCollection", JoinType.LEFT);
Join<EcoleJournee, Journee> j = ej.join("journee", JoinType.LEFT);
Expression<Number> expDateLimiteInscrMax = cb.max(cb.coalesce(ej.get("dateLimiteInscription").as(Number.class), j.get("dateLimiteInscription").as(Number.class)));
c.having(cb.ge(expDateLimiteInscrMax, 1234567890);
If I use a multiselect like this "c.multiselect(ec, expDateLimiteInscrMax).groupBy(ec);" for this query, without nested fetch, the query works and the having clause is not ignored.
Finally, I tried to use a subquery but I can't get a simple example to run. Anyone have an idea?
Thanks
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01836 seconds