OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.16k stars 599 forks source link

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

Open njr-11 opened 5 months ago

njr-11 commented 5 months ago

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.

[6/26/24, 13:28:23:280 CDT] 0000005c id=5bf7c5bf io.openliberty.data.internal.persistence.RepositoryImpl      3 QueryInfo@bb8bfa2 boolean setFirstNameInCurrentTransaction(Long, String) UPDATE Person SET firstName=:newFirstName WHERE id(this)=:ssn [2 named params]
[6/26/24, 13:28:23:280 CDT] 0000005c id=3c7e2187 enliberty.data.internal.persistence.service.DBStoreEMBuilder > createEntityManager Entry 
[6/26/24, 13:28:23:280 CDT] 0000005c id=11fcd700 om.ibm.wsspi.persistence.internal.PersistenceServiceUnitImpl > createEntityManager Entry 
[6/26/24, 13:28:23:280 CDT] 0000005c id=11fcd700 om.ibm.wsspi.persistence.internal.PersistenceServiceUnitImpl < createEntityManager Exit  
                                                                                                               org.eclipse.persistence.internal.jpa.EntityManagerImpl@3a3f6a52
[6/26/24, 13:28:23:280 CDT] 0000005c id=3c7e2187 enliberty.data.internal.persistence.service.DBStoreEMBuilder < createEntityManager Exit  
                                                                                                               org.eclipse.persistence.internal.jpa.EntityManagerImpl@3a3f6a52
[6/26/24, 13:28:23:280 CDT] 0000005c id=00000000 io.openliberty.data.internal.persistence.RepositoryImpl      3 java.lang.IllegalArgumentException replaced with jakarta.data.exceptions.MappingException
[6/26/24, 13:28:23:280 CDT] 0000005c id=5bf7c5bf io.openliberty.data.internal.persistence.RepositoryImpl      < invoke PersonRepo.setFirstNameInCurrentTransaction Exit  
                                                                                                               jakarta.data.exceptions.MappingException: 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 io.openliberty.data.internal.persistence.RepositoryImpl.failure(RepositoryImpl.java:302)
    at io.openliberty.data.internal.persistence.RepositoryImpl.invoke(RepositoryImpl.java:1256)
    at jdk.proxy14/jdk.proxy14.$Proxy59.setFirstNameInCurrentTransaction(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:55)
    at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:86)
    at com.ibm.tx.jta.cdi.interceptors.TransactionalInterceptor$2.run(TransactionalInterceptor.java:176)
    at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderCurrentUOW(EmbeddableUOWManagerImpl.java:1079)
    at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderUOW(EmbeddableUOWManagerImpl.java:1017)
    at com.ibm.tx.jta.cdi.interceptors.TransactionalInterceptor.runUnderUOWManagingEnablement(TransactionalInterceptor.java:190)
    at com.ibm.tx.jta.cdi.interceptors.Mandatory.mandatory(Mandatory.java:47)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:75)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:90)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:73)
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:80)
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
    at org.jboss.weld.bean.proxy.InterceptedProxyMethodHandler.invoke(InterceptedProxyMethodHandler.java:61)
    at test.jakarta.data.web.PersonRepo$Proxy$_$$_WeldInterceptedProxy4.setFirstNameInCurrentTransaction(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:38)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:109)
    at test.jakarta.data.web.PersonRepo$844246649$Proxy$_$$_WeldClientProxy.setFirstNameInCurrentTransaction(Unknown Source)
    at test.jakarta.data.web.DataTestServlet.testTransactional(DataTestServlet.java:4869)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    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.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1266)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:754)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:451)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1362)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1078)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:77)
    at com.ibm.ws.webcontainer40.servlet.CacheServletWrapper40.handleRequest(CacheServletWrapper40.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:978)
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:293)
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:1260)
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:476)
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:435)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:569)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:503)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:363)
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:330)
    at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:169)
    at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:77)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:516)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:586)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:970)
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1059)
    at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:280)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)
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 commented 5 months ago

See EclipseLink Issue : 2184

Riva-Tholoor-Philip commented 3 months ago

@KyleAure - What is the positive scenario with Entity Identification Variable? I tried the following queries, but not working: 1) UPDATE Person p SET p.firstName=:newFirstName WHERE p.ssn_id=:ssn 2) UPDATE Person p SET p.firstName=:newFirstName WHERE id(p)=:ssn

KyleAure commented 3 months ago

UPDATE Person p SET p.firstName=:newFirstName WHERE p.ssn_id=:ssn