Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException with nested fetch join and multiselect
NullPointerException with nested fetch join and multiselect [message #539404] Thu, 10 June 2010 15:46 Go to next message
Patrice Lachance is currently offline Patrice LachanceFriend
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
Re: NullPointerException with nested fetch join and multiselect [message #539615 is a reply to message #539404] Fri, 11 June 2010 13:59 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Any chance you can run on the latest nightly build just to see the stack (the nightly for 2.1 contains some refactoring in the fetch join code)? Please file a bug and remember to vote for it.

As for the second query, having+group support seems to have been excluded when querying managed entities with a simple query. Please file a bug to have an error or a message logged or support added, rather than just ignoring the clause.

As a workaround, try the first query but have it return an entity and a literal:
c.multiselect(ec, cb.literal(1)).groupBy(ec);
I haven't tried it, but should work around both problems in theory.

Best Regards,
Chris
Re: NullPointerException with nested fetch join and multiselect [message #539636 is a reply to message #539404] Fri, 11 June 2010 15:00 Go to previous message
Patrice Lachance is currently offline Patrice LachanceFriend
Messages: 6
Registered: June 2010
Junior Member
Hi,

I've tried the first query with the latest version I could find easily (eclipselink-2.1.0-20100609.213134-142) and there's no more exception. The query works fine now.

For the second query, it has the same behavior with v2.1 but your workaroung is working. I'll file a bug report.

Version 2.1 even solved a third bug I had with CriteriaBuilder.construct().

Thanks for your support.
Previous Topic:historical query - only Oracle 9R2 or later?
Next Topic:potential memory leak persisting objects with eclipselink 2
Goto Forum:
  


Current Time: Thu Apr 18 15:41:19 GMT 2024

Powered by FUDForum. Page generated in 0.01836 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top