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.14k stars 587 forks source link

SVT:Not providing Entity in JPQL causes java.lang.ClassCastException #29319

Open rumanaHaque opened 1 month ago

rumanaHaque commented 1 month ago

Describe the bug
I tried using the new way of specifying queries in JPQL. I used

<named-query name="GetHolderAnnuities">
        <query>FROM Annuity WHERE annuityHolderId = :holderId</query> 
</named-query>

Prev I had used this statement, and that worked. <query>SELECT a FROM Annuity AS a WHERE a.annuityHolderId = :holderId</query>

Even when I tried adding SELECT this in front of the query, it still failed. <query>SELECT this FROM Annuity WHERE annuityHolderId = :holderId</query>

If there is a stack trace, please include the FULL stack trace (without any [internal classes] lines in it). To find the full stack trace, you may need to check in $WLP_OUTPUT_DIR/messages.log This is what I see in the logs:

[INFO] [ERROR   ] CWWJP0015E: An error occurred in the org.eclipse.persistence.jpa.PersistenceProvider persistence provider when it attempted to create the container entity manager factory for the AnnuityDSJPAOnly persistence unit. The following error occurred: Exception [EclipseLink-28018] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.EntityManagerSetupException
[INFO] Exception Description: Predeployment of PersistenceUnit [AnnuityDSJPAOnly] failed.
[INFO] Internal Exception: Exception [EclipseLink-7158] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.ValidationException
[INFO] Exception Description: Error encountered when building the @NamedQuery [GetHolderAnnuities] from entity class [class org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata].
[INFO] Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.jpa.jpql.parser.NullExpression incompatible with org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable

Steps to Reproduce
For a named query, use the new way of defining JPQL For e.g. FROM Annuity WHERE annuityHolderId = :holderId instead of SELECT a FROM Annuity AS a WHERE a.annuityHolderId = :holderId Expected behavior
This new way of using JPQL should work without any issues.

Diagnostic information:

Additional context
Here is the ffdc for the error:

------Start of DE processing------ = [8/7/24, 11:29:05:593 CDT ]
Exception = jakarta.persistence.PersistenceException
Source = com.ibm.ws.jpa.management.JPAPUnitInfo.createEMFactory
probeid = 759
Stack Dump = jakarta.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [AnnuityDSJPAOnly] failed.
Internal Exception: Exception [EclipseLink-7158] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered when building the @NamedQuery [GetHolderAnnuities] from entity class [class org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata].
Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.jpa.jpql.parser.NullExpression incompatible with org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:2157)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2133)
        at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactoryImpl(PersistenceProvider.java:390)
        at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:354)
        at com.ibm.ws.jpa.management.JPAPUnitInfo.createEMFactory(JPAPUnitInfo.java:984)
        at com.ibm.ws.jpa.management.JPAPUnitInfo.initialize(JPAPUnitInfo.java:819)
        at com.ibm.ws.jpa.management.JPAPxmlInfo.extractPersistenceUnits(JPAPxmlInfo.java:190)
        at com.ibm.ws.jpa.management.JPAScopeInfo.processPersistenceUnit(JPAScopeInfo.java:90)
        at com.ibm.ws.jpa.management.JPAApplInfo.addPersistenceUnits(JPAApplInfo.java:121)
        at com.ibm.ws.jpa.container.osgi.internal.JPAComponentImpl.processEJBModulePersistenceXml(JPAComponentImpl.java:651)
        at com.ibm.ws.jpa.container.osgi.internal.JPAComponentImpl.applicationStarting(JPAComponentImpl.java:377)
        at com.ibm.ws.container.service.state.internal.ApplicationStateManager.fireStarting(ApplicationStateManager.java:53)
        at com.ibm.ws.container.service.state.internal.StateChangeServiceImpl.fireApplicationStarting(StateChangeServiceImpl.java:52)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.preDeployApp(SimpleDeployedAppInfoBase.java:550)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.installApp(SimpleDeployedAppInfoBase.java:511)
        at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:625)
        at com.ibm.ws.app.manager.ear.internal.EARApplicationHandlerImpl.install(EARApplicationHandlerImpl.java:79)
        at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:199)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1369)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:912)
        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:1639)
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [AnnuityDSJPAOnly] failed.
Riva-Tholoor-Philip commented 3 weeks ago

@rumanaHaque - The issue is fixed with the latest Eclipselink snapshot. Ref Issue 29394 Can you please check and verify at your end

rumanaHaque commented 3 weeks ago

I just retried this test - using this build - https://rtpgsa.ibm.com/projects/l/liberty.build/liberty/WASX.LIBERTY/daily/cl240920240821-0303.07.linux/linux/zipper/externals/installables/openliberty-24.0.0.10-beta-cl240920240821-0303.zip, but I still see the same error. Could you please provide with a link to a build that has the fix for this defect?

rumanaHaque commented 2 weeks ago

I did try this using one of the later drivers - which has an updated EclipseLink (5.0.0.v202408200932)version, but I still see the same error.

[INFO] [ERROR   ] CWWJP0015E: An error occurred in the org.eclipse.persistence.jpa.PersistenceProvider persistence provider when it attempted to create the container entity manager factory for the PolicySAJPAOnly persistence unit. The following error occurred: Exception [EclipseLink-28018] (Eclipse Persistence Services - 5.0.0.v202408200932-f556522e743c87b8097f78cefe2b8f24f68cf79e): org.eclipse.persistence.exceptions.EntityManagerSetupException
[INFO] Exception Description: Predeployment of PersistenceUnit [PolicySAJPAOnly] failed.
[INFO] Internal Exception: Exception [EclipseLink-7158] (Eclipse Persistence Services - 5.0.0.v202408200932-f556522e743c87b8097f78cefe2b8f24f68cf79e): org.eclipse.persistence.exceptions.ValidationException
[INFO] Exception Description: Error encountered when building the @NamedQuery [GetHolderAnnuities] from entity class [class org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata].
[INFO] Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.jpa.jpql.parser.NullExpression incompatible with org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable

Is this the correct EclipseLink version which has the fix for this defect?

rumanaHaque commented 2 weeks ago

The error for this defect I think is using the createNamedQuery - instead of using the actual query itself.

This is what I had in my original code;

factory = super.getEntityManagerFactory(holder);                    
em = factory.createEntityManager();
Query query = em.createNamedQuery("GetHolderAnnuities");            
query.setParameter("holderId", holder.getId());
List l = (List<IAnnuity>) query.getResultList();
return l;

I modified the code - to create the Query in the code itself, instead of creating a named Query.

factory = super.getEntityManagerFactory(holder);                    
em = factory.createEntityManager();
Query query = em.createQuery("FROM Annuity WHERE annuityHolderId = :holderId");
query.setParameter("holderId", holder.getId());
List l = (List<IAnnuity>) query.getResultList();
return l;

This new code seems to start without any exceptions.