Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when JPQL UPDATE assignment operation omits optional identification variable #2184

Closed
Riva-Tholoor-Philip opened this issue Jul 2, 2024 · 7 comments · Fixed by #2254

Comments

@Riva-Tholoor-Philip
Copy link
Contributor

The JPQL UPDATE query UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn which optionally omits the entity identification variable (for consistency with JDQL) gets NullPointerException out of EclipseLink.

Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Internal problem encountered while compiling [UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn].
Internal Exception: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.jpa.jpql.Declaration.getDescriptor()" because the return value of "org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.getDeclaration(String)" is null
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1848)
	at io.openliberty.data.internal.persistence.RepositoryImpl.invoke(RepositoryImpl.java:1079)
	... 57 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Internal problem encountered while compiling [UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn].
Internal Exception: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.jpa.jpql.Declaration.getDescriptor()" because the return value of "org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.getDeclaration(String)" is null
	at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildUnexpectedException(HermesParser.java:215)
	at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:310)
	at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:174)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:120)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:107)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:91)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1846)
	... 58 more
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.jpa.jpql.Declaration.getDescriptor()" because the return value of "org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.getDeclaration(String)" is null
	at org.eclipse.persistence.internal.jpa.jpql.JPQLFunctionsAbstractBuilder.visit(JPQLFunctionsAbstractBuilder.java:64)
	at org.eclipse.persistence.jpa.jpql.parser.IdExpression.accept(IdExpression.java:46)
	at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor$ComparisonExpressionVisitor.visit(ExpressionBuilderVisitor.java:2208)
	at org.eclipse.persistence.jpa.jpql.parser.AnonymousExpressionVisitor.visit(AnonymousExpressionVisitor.java:231)
	at org.eclipse.persistence.jpa.jpql.parser.IdExpression.accept(IdExpression.java:46)
	at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor.visit(ExpressionBuilderVisitor.java:732)
	at org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression.accept(ComparisonExpression.java:71)
	at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor.visit(ExpressionBuilderVisitor.java:2111)
	at org.eclipse.persistence.jpa.jpql.parser.WhereClause.accept(WhereClause.java:56)
	at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor.buildExpression(ExpressionBuilderVisitor.java:280)
	at org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.buildExpression(JPQLQueryContext.java:326)
	at org.eclipse.persistence.internal.jpa.jpql.AbstractModifyAllQueryBuilder.visit(AbstractModifyAllQueryBuilder.java:77)
	at org.eclipse.persistence.jpa.jpql.parser.WhereClause.accept(WhereClause.java:56)
	at org.eclipse.persistence.internal.jpa.jpql.UpdateQueryVisitor.visit(UpdateQueryVisitor.java:77)
	at org.eclipse.persistence.jpa.jpql.parser.UpdateStatement.accept(UpdateStatement.java:65)
	at org.eclipse.persistence.internal.jpa.jpql.HermesParser$DatabaseQueryVisitor.visit(HermesParser.java:461)
	at org.eclipse.persistence.jpa.jpql.parser.UpdateStatement.accept(UpdateStatement.java:65)
	at org.eclipse.persistence.internal.jpa.jpql.HermesParser$DatabaseQueryVisitor.visit(HermesParser.java:423)
	at org.eclipse.persistence.jpa.jpql.parser.JPQLExpression.accept(JPQLExpression.java:186)
	at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:296)
	... 64 more
@Riva-Tholoor-Philip
Copy link
Contributor Author

I could recreate the issue.

Below is the Person entity we have by referencing the entity present in Jakarta Data.

@Entity
public class Person {

    @Id
    public long ssn_id;
    public String firstName;
    public String lastName;
}

Here is the code where we executed the JPQL query:

public void testOLGH28908() throws Exception {
        Person p = new Person();
        p.firstName = "John";
        p.lastName = "Jacobs";
        p.ssn_id = 111111111l;

        Person result;

        tx.begin();

        try {
            em.persist(p);

            em.createQuery("UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn")
                            .setParameter("newFirstName", "Jack")
                            .setParameter("ssn", p.ssn_id)
                            .executeUpdate();

            result = em.createQuery("SELECT Person WHERE ssn_id=:ssn", Person.class)
                            .setParameter("ssn", p.ssn_id)
                            .getSingleResult();

            tx.commit();
        } catch (Exception e) {
            tx.rollback();

            throw e;
        }

This resulted in the following exception stack, which is the same as described in the issue:

Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Internal problem encountered while compiling [UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn].
Internal Exception: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.jpa.jpql.Declaration.getDescriptor()" because the return value of "org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.getDeclaration(java.lang.String)" is null
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildUnexpectedException(HermesParser.java:215)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:310)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:174)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:120)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:107)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:91)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1846)
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.jpa.jpql.Declaration.getDescriptor()" because the return value of "org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.getDeclaration(java.lang.String)" is null
at org.eclipse.persistence.internal.jpa.jpql.JPQLFunctionsAbstractBuilder.visit(JPQLFunctionsAbstractBuilder.java:64)
at org.eclipse.persistence.jpa.jpql.parser.IdExpression.accept(IdExpression.java:46)
at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor$ComparisonExpressionVisitor.visit(ExpressionBuilderVisitor.java:2208)
at org.eclipse.persistence.jpa.jpql.parser.AnonymousExpressionVisitor.visit(AnonymousExpressionVisitor.java:231)
at org.eclipse.persistence.jpa.jpql.parser.IdExpression.accept(IdExpression.java:46)
at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor.visit(ExpressionBuilderVisitor.java:732)
at org.eclipse.persistence.jpa.jpql.parser.ComparisonExpression.accept(ComparisonExpression.java:71)
at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor.visit(ExpressionBuilderVisitor.java:2111)
at org.eclipse.persistence.jpa.jpql.parser.WhereClause.accept(WhereClause.java:56)
at org.eclipse.persistence.internal.jpa.jpql.ExpressionBuilderVisitor.buildExpression(ExpressionBuilderVisitor.java:280)
at org.eclipse.persistence.internal.jpa.jpql.JPQLQueryContext.buildExpression(JPQLQueryContext.java:326)
at org.eclipse.persistence.internal.jpa.jpql.AbstractModifyAllQueryBuilder.visit(AbstractModifyAllQueryBuilder.java:77)
at org.eclipse.persistence.jpa.jpql.parser.WhereClause.accept(WhereClause.java:56)
at org.eclipse.persistence.internal.jpa.jpql.UpdateQueryVisitor.visit(UpdateQueryVisitor.java:77)
at org.eclipse.persistence.jpa.jpql.parser.UpdateStatement.accept(UpdateStatement.java:65)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser$DatabaseQueryVisitor.visit(HermesParser.java:461)
at org.eclipse.persistence.jpa.jpql.parser.UpdateStatement.accept(UpdateStatement.java:65)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser$DatabaseQueryVisitor.visit(HermesParser.java:423)
at org.eclipse.persistence.jpa.jpql.parser.JPQLExpression.accept(JPQLExpression.java:186)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:296)

@Riva-Tholoor-Philip
Copy link
Contributor Author

I am working on this issue

@rfelcman
Copy link
Contributor

rfelcman commented Aug 6, 2024

@Riva-Tholoor-Philip
Copy link
Contributor Author

We checked with latest snapshot, but the test is still failing.

@lukasj
Copy link
Member

lukasj commented Aug 21, 2024

we need the new stacktrace here

@Riva-Tholoor-Philip
Copy link
Contributor Author

@lukasj - Please find the stacktrace:

Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.JPQLException

Exception Description: Syntax error parsing [UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn].
[53, 57] The encapsulated expression is not a valid expression. (UPDATE Person SET firstName = :newFirstName WHERE id( [ id(this) ] ...
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:175)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:358)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:298)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:180)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:120)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.(EJBQueryImpl.java:107)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.(EJBQueryImpl.java:91)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1846)
... 36 more

rfelcman added a commit to rfelcman/eclipselink that referenced this issue Aug 30, 2024
…ional identification variable eclipse-ee4j#2184  - fix

Signed-off-by: Radek Felcman <[email protected]>
rfelcman added a commit to rfelcman/eclipselink that referenced this issue Sep 3, 2024
…ional identification variable eclipse-ee4j#2184  - bug fix (main + tests)

Signed-off-by: Radek Felcman <[email protected]>
joe-chacko pushed a commit to joe-chacko/eclipselink that referenced this issue Sep 5, 2024
…ional identification variable eclipse-ee4j#2184  - bug fix (main + tests)

Signed-off-by: Radek Felcman <[email protected]>
@Riva-Tholoor-Philip
Copy link
Contributor Author

Riva-Tholoor-Philip commented Sep 6, 2024

The test is failing in Open Liberty. We will do another round of testing after integrating snapshot. Please refer the stacktrace:

junit.framework.AssertionFailedError: 2024-09-06-19:13:37:536 ERROR: Caught exception attempting to call test method testOLGH28908 on servlet io.openliberty.jpa.data.tests.web.JakartaDataRecreateServlet
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn].
[53, 57] The encapsulated expression is not a valid expression. (UPDATE Person SET firstName = :newFirstName WHERE id( [ id(this) ] ...
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1848)
at [com.ibm.ws](http://com.ibm.ws/).jpa.management.JPATxEmInvocation.createQuery(JPATxEmInvocation.java:195)
at [com.ibm.ws](http://com.ibm.ws/).jpa.management.JPAEntityManager.createQuery(JPAEntityManager.java:319)
at io.openliberty.jpa.data.tests.web.JakartaDataRecreateServlet.testOLGH28908(JakartaDataRecreateServlet.java:186)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at componenttest.app.FATServlet.doGet(FATServlet.java:74)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:633)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:723)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1266)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:754)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:451)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1362)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1078)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:77)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer40.servlet.CacheServletWrapper40.handleRequest(CacheServletWrapper40.java:87)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.WebContainer.handleRequest(WebContainer.java:978)
at [com.ibm.ws](http://com.ibm.ws/).webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:293)
at [com.ibm.ws](http://com.ibm.ws/).http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:1260)
at [com.ibm.ws](http://com.ibm.ws/).http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:476)
at [com.ibm.ws](http://com.ibm.ws/).http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:435)
at [com.ibm.ws](http://com.ibm.ws/).http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:569)
at [com.ibm.ws](http://com.ibm.ws/).http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:503)
at [com.ibm.ws](http://com.ibm.ws/).http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:363)
at [com.ibm.ws](http://com.ibm.ws/).http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:330)
at [com.ibm.ws](http://com.ibm.ws/).tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:169)
at [com.ibm.ws](http://com.ibm.ws/).tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:77)
at [com.ibm.ws](http://com.ibm.ws/).tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:516)
at [com.ibm.ws](http://com.ibm.ws/).tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:586)
at [com.ibm.ws](http://com.ibm.ws/).tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:970)
at [com.ibm.ws](http://com.ibm.ws/).tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1059)
at [com.ibm.ws](http://com.ibm.ws/).threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:298)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:857)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0.v202408200932-f556522e743c87b8097f78cefe2b8f24f68cf79e): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn].
[53, 57] The encapsulated expression is not a valid expression. (UPDATE Person SET firstName = :newFirstName WHERE id( [ id(this) ] ...
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:175)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:351)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:298)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:180)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:120)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:107)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:91)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1846)
at componenttest.topology.utils.FATServletClient.assertTestResponse(FATServletClient.java:106)
at componenttest.topology.utils.FATServletClient.runTest(FATServletClient.java:91)
at componenttest.custom.junit.runner.SyntheticServletTest.invokeExplosively(SyntheticServletTest.java:49)
at componenttest.custom.junit.runner.FATRunner$1.evaluate(FATRunner.java:209)
at componenttest.custom.junit.runner.FATRunner$2.evaluate(FATRunner.java:374)
at componenttest.custom.junit.runner.FATRunner.run(FATRunner.java:178)
at org.testcontainers.containers.FailureDetectingExternalResource$1.evaluate(FailureDetectingExternalResource.java:29)
at componenttest.rules.repeater.RepeatTests$CompositeRepeatTestActionStatement.evaluate(RepeatTests.java:149)

rfelcman added a commit to rfelcman/eclipselink that referenced this issue Sep 9, 2024
…ional identification variable eclipse-ee4j#2184  - bug fix (main + tests)

Signed-off-by: Radek Felcman <[email protected]>
rfelcman added a commit to rfelcman/eclipselink that referenced this issue Sep 9, 2024
…ipse-ee4j#2192 issues

JPQL SELECT not allowing entity attribute without optional entity identification variable eclipse-ee4j#2182 - bug fix (main + tests)
NullPointerException when JPQL UPDATE assignment operation omits optional identification variable eclipse-ee4j#2184 - bug fix (main + tests)
Unable to omit optional entity identification variable from arguments to built-in aggregate functions eclipse-ee4j#2192 - bug fix (main + tests)

Signed-off-by: Radek Felcman <[email protected]>
rfelcman added a commit to rfelcman/eclipselink that referenced this issue Sep 10, 2024
…e-ee4j#2192, eclipse-ee4j#2247 issues

JPQL SELECT not allowing entity attribute without optional entity identification variable eclipse-ee4j#2182 - bug fix (main + tests)
NullPointerException when JPQL UPDATE assignment operation omits optional identification variable eclipse-ee4j#2184 - bug fix (main + tests)
Unable to omit optional entity identification variable from arguments to built-in aggregate functions eclipse-ee4j#2192 - bug fix (main + tests)
Arithmetic expressions in SELECT clause broken when entity identifier variable omitted eclipse-ee4j#2247 - bug fix (main + tests)

Signed-off-by: Radek Felcman <[email protected]>
rfelcman added a commit that referenced this issue Sep 11, 2024
JPQL SELECT not allowing entity attribute without optional entity identification variable #2182 - bug fix (main + tests)
NullPointerException when JPQL UPDATE assignment operation omits optional identification variable #2184 - bug fix (main + tests)
Unable to omit optional entity identification variable from arguments to built-in aggregate functions #2192 - bug fix (main + tests)
Arithmetic expressions in SELECT clause broken when entity identifier variable omitted #2247 - bug fix (main + tests)

Signed-off-by: Radek Felcman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants