Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException in Query.setHint with join-fetch/batch(NullPointerException at ObjectExpression.existingDerivedExpressionNamed(ObjectExpression.java:254))
NullPointerException in Query.setHint with join-fetch/batch [message #757300] Thu, 17 November 2011 15:31 Go to next message
Sven Hoffmann is currently offline Sven HoffmannFriend
Messages: 18
Registered: July 2009
Junior Member
Sometimes a NullPointerException occures while creating a JPA query with query hint eclipselink.join-fetch/eclipselink.batch.

The code performing the query looks like:
Query query = em.createNamedQuery(Container.LOAD_BY_ORDER);
query.setParameter("orderId", id);
query.setHint(QueryHints.FETCH, "c.attribute1");
query.setHint(QueryHints.BATCH, "c.attribute3");
List result = query.getResultList();


The stacktrace of the exception is:
java.lang.NullPointerException
at org.eclipse.persistence.internal.expressions.ObjectExpression.existingDerivedExpressionNamed(ObjectExpression.java:254)
at org.eclipse.persistence.internal.expressions.ObjectExpression.derivedExpressionNamed(ObjectExpression.java:223)
at org.eclipse.persistence.internal.expressions.ObjectExpression.get(ObjectExpression.java:267)
at org.eclipse.persistence.expressions.Expression.get(Expression.java:1529)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler$FetchHint.applyToDatabaseQuery(QueryHintsHandler.java:1376)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler$Hint.apply(QueryHintsHandler.java:361)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler$Hint.apply(QueryHintsHandler.java:339)
at org.eclipse.persistence.internal.jpa.QueryHintsHandler.apply(QueryHintsHandler.java:171)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setHintInternal(EJBQueryImpl.java:1021)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setHint(EJBQueryImpl.java:1003)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setHint(EJBQueryImpl.java:81)
...


The application uses EclipseLink 2.3.1 M8 and is hosted on WebSphere Application Server 7.0 FP17 on an AIX system. The query is concurrently performed by message driven beans.
After one failure all subsequent calls fail with the same exception until the server is restarted.

I've found a similar issue described in NullPointerException in QueryKeyExpression.getQueryKeyOrNull.

It is possible to avoid this exception e.g. by JPA configuration (disable expression cache) or is a fix available?

[Updated on: Sat, 19 November 2011 17:24]

Report message to a moderator

Re: Title: NullPointerException in Query.setHint with join-fetch/batch [message #758044 is a reply to message #757300] Mon, 21 November 2011 19:53 Go to previous message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
The issue is although the hint causes different queries to be used, the same expression is still used, causing the concurrency issue.

Can you set the hint in the named query instead of dynamically (otherwise you are really not sharing the same query). If you have some queries that use join fetch, and some the use batch, then create multiple different named queries. Or use a dynamic JPQL query instead of changing a static defined one.

You could also synchronize on the DatabaseQuery's ExpressionBuilder while setting the hint. Please log a bug to have the concurrency issue fixed.


You can disable the JPQL cache using,

session.getProject().setJPQLParseCacheMaxSize(0);


--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:Title: NullPointerException in Query.setHint with join-fetch/batch
Next Topic:JPA query - NOT MEMBER OF exception
Goto Forum:
  


Current Time: Sat Dec 20 03:53:15 GMT 2014

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

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