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) still not accepted in ORDER BY clause #2297

Open
anija-anil opened this issue Nov 8, 2024 · 1 comment
Open

id(this) still not accepted in ORDER BY clause #2297

anija-anil opened this issue Nov 8, 2024 · 1 comment

Comments

@anija-anil
Copy link
Contributor

EclipseLink is not accepting the id(this) operation, which is new in Jakarta Persistence 3.2, when it is placed within a JPQL ORDER BY clause.

SELECT ID(THIS) FROM Prime WHERE ID(THIS) < ?1 ORDER BY ID(THIS) DESC

Here is the error:

Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0-B03.v202409121024-4a7149f0cd04d7466837d70f68abb743c88acb83): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [SELECT ID(THIS) FROM Prime WHERE ID(THIS) < ?1 ORDER BY ID(THIS) DESC]. 
[56, 64] The order by item is not a valid expression. (SELECT ID(THIS) FROM Prime WHERE ID(THIS) < ?1 ORDER BY  [ 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)
	... 44 more
@rfelcman
Copy link
Contributor

I retested this issue by:

    @Test
    public void queryTestSelectAndGeneratedThisOrderByIdFunction() {
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(PU_NAME);
        assertNotNull(entityManagerFactory);

        EntityManager em = entityManagerFactory.createEntityManager();
        em.getTransaction().begin();

        try {
            Query query = em.createQuery("SELECT ID(THIS) FROM NoAliasEntity WHERE ID(THIS) < ?1 ORDER BY ID(THIS) DESC");
            query.setParameter(1, ID + 10);
            List<Long> results = query.getResultList();
            assertEquals(2, results.size());
            em.getTransaction().rollback();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        } finally {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }

and it seems that is fixed by #2278 and #2287 . Please try latest snapshot like eclipselink-5.0.0-20241114.084709-72.jar

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

No branches or pull requests

2 participants