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

Error execution delete operation without identification_variable #1727

Closed
bvfalcon opened this issue Oct 6, 2022 · 4 comments · Fixed by #1729
Closed

Error execution delete operation without identification_variable #1727

bvfalcon opened this issue Oct 6, 2022 · 4 comments · Fixed by #1729
Assignees

Comments

@bvfalcon
Copy link

bvfalcon commented Oct 6, 2022

By executing DELETE FROM entity_name Eclipselink 3.0.3 gives a NullPointerException error. But execution DELETE FROM entity_name x works correctly.

Identification variable is required, but specification defines it as optional.

See demonstration project for details.

Environment:

  • Eclipselink 3.0.3
  • Derby database driver 10.15
  • Java 11
@Tomas-Kraus Tomas-Kraus self-assigned this Oct 11, 2022
@Tomas-Kraus
Copy link
Member

Added simple jUnit into development branch:

    @Test
    public void testDeleteEntityWithoutAlias() {
        final String jpql = "DELETE FROM SimpleEntity";
        final EntityManager em = emf.createEntityManager();
        try {
            em.getTransaction().begin();
            Query q = em.createQuery(jpql);
            q.executeUpdate();
            em.getTransaction().commit();
        } finally {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }

And this test passed:

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.012 s - in org.eclipse.persistence.jpa.test.jpql.TestBasicJPQL

So looks like future 4.0 is OK.
Will try 3.x branch now.

Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Oct 11, 2022
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
@bvfalcon
Copy link
Author

bvfalcon commented Oct 12, 2022

Yes, you are right, JUnit-test works correctly. My initial description was incorrect
I did found an error. Compare 3 cases in Table:

N Command Result
1 DELETE FROM SimpleEntity correct
2 DELETE FROM org.eclipse.persistence.jpa.test.jpql.model.SimpleEntity error
3 DELETE FROM org.eclipse.persistence.jpa.test.jpql.model.SimpleEntity o correct

Case 1 fully corresponds to specification, but cases 2-3 - not. For this reason is strange, that in case 2 we have an error, but in case 3 we have correct result.

Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Oct 12, 2022
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
@Tomas-Kraus
Copy link
Member

OK, I was able to reproduce this. Modified PR #1729 to contain fix and tests for both FQN cases. We need them covered for the future.

Tomas-Kraus added a commit to Tomas-Kraus/eclipselink that referenced this issue Oct 12, 2022
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
@dazey3
Copy link
Contributor

dazey3 commented Nov 2, 2022

Are we sure the JPA Specification intended to allow for:

    Query query = em.createQuery("DELETE FROM Employee WHERE firstName = :fName AND lastName = :lName");
    query.setParameter("fName", "Peter");
    query.setParameter("lName", "Parker");
    query.executeUpdate();

The examples provided in the specification don't specifically include one where no identification variable is supplied and this query syntax looks more like a NativeQuery than a JPQL one... I know that isn't necessarily concrete evidence, but this query just looks incorrect to me.

I wonder if the JPA Specification is incorrect, or rather not verbose enough to describe the real intention; something like:

    delete_statement ::= simple_delete_clause | where_delete_clause where_clause
    simple_delete_clause := DELETE FROM entity_name [[AS] identification_variable]
    where_delete_clause := DELETE FROM entity_name [AS] identification_variable

IOW: if you don' supply a where_clause, you don't need to provide an identification_variable; we can figure it out for you. But if you do have a WHERE clause, you need identification_variables.

I don't know. What is the usecase of supporting two different syntax in JPQL that do the same thing and are negligibly different? Why support both:

    em.createQuery("DELETE FROM Employee WHERE firstName = :fName AND lastName = :lName");

and

    em.createQuery("DELETE FROM Employee e WHERE e.firstName = :fName AND e.lastName = :lName");

lukasj pushed a commit to lukasj/eclipselink that referenced this issue Dec 6, 2022
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
lukasj pushed a commit that referenced this issue Dec 6, 2022
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
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