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

id(this) is not accepted as an argument to a function #2286

Closed
anija-anil opened this issue Oct 21, 2024 · 2 comments · Fixed by #2287
Closed

id(this) is not accepted as an argument to a function #2286

anija-anil opened this issue Oct 21, 2024 · 2 comments · Fixed by #2287

Comments

@anija-anil
Copy link
Contributor

EclipseLink is not accepting the ID(THIS) operation when supplied as an argument to another JPQL function, such as LOWER,

FROM Vehicle WHERE LOWER(ID(THIS)) = ?1

The error raised is:


java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing [ FROM Vehicle WHERE LOWER(ID(THIS)) = ?1]. 
[37, 45] The encapsulated expression is not a valid expression. (SELECT this FROM Vehicle WHERE LOWER( [ LOWER(ID(THIS)) ] ...
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1848)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1869)
	at io.openliberty.data.internal.persistence.RepositoryImpl.invoke(RepositoryImpl.java:1133)
	... 38 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0-B03.v202409121024-4a7149f0cd04d7466837d70f68abb743c88acb83): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [ FROM Vehicle WHERE LOWER(ID(THIS)) = ?1]. 
[37, 45] The encapsulated expression is not a valid expression. (SELECT this FROM Vehicle WHERE LOWER( [ LOWER(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)
	... 40 more
@rfelcman
Copy link
Contributor

See pull request above. I see one issue with provided example ....WHERE LOWER(ID(THIS)) = .... This example is not type safe. It should fail if result from ID(THIS) will be some numeric type. This is why in my tests in PR #2287 is ID( wrapped by CAST (.

@ajaypaul-ibm
Copy link
Contributor

Hi @rfelcman Please find below entity

public class Vehicle {
    public String make;

    public String model;

    public int numSeats;

    public float price;

    public String vinId;
}

Here vinId is the id which is already a String.

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