Skip to content

JPQL aliasing using id breaks EclipseLink queries #4167

@hgwr

Description

@hgwr

Summary

After upgrading to Spring Boot 4.x (Spring Data JPA 4.0.x) with EclipseLink 5.0.0-B13, some derived queries fail at runtime.
This issue appears to be separate from #4145 (IN clause list binding).

Background / Regression

We recently upgraded our project from Spring Boot 3.x to 4.x.
After the upgrade, several repository methods based on derived queries started failing at runtime unless rewritten using explicit @Query JPQL.

This suggests a regression or compatibility gap introduced by the combination of Spring Data JPA 4.x and EclipseLink 5 (Hermes JPQL parser).

Actual behavior

1. existsBy… derived queries fail with JPQL syntax error

EclipseLink 5 (Hermes) rejects JPQL generated for existsBy… queries due to an implicit alias in the select clause.

Example exception:

BadJpqlGrammarException: ... Syntax error parsing ... select o.id id ...

Generated JPQL (example):

SELECT o.id id FROM OfUser o
WHERE UPPER(o.email) = UPPER(?1)
  AND o.id != ?2
  AND o.isDelete != ?3

Hermes appears to reject select o.id id (implicit alias without AS).

2. Parameter mismatch in findByIdAndIsDeleted

Some derived queries fail with a positional parameter binding error:

InvalidDataAccessApiUsageException:
Query argument 2 not found in the list of parameters provided during query execution

This seems to indicate that EclipseLink 5 under-reports positional parameters for certain derived queries.

Expected behavior

Derived queries should execute successfully on EclipseLink 5 without requiring explicit JPQL annotations.

Steps to reproduce (minimal)

Entity

@Entity
class SoftDeleteUser {

  @Id
  @GeneratedValue
  Long id;

  @Column(nullable = false)
  String email;

  @Column(nullable = false)
  Integer isDeleted;
}

Repository

interface SoftDeleteUserRepository
    extends JpaRepository<SoftDeleteUser, Long> {

  boolean existsByEmailIgnoreCaseAndIdNotAndIsDeletedNot(
      String email, Long id, Integer isDeleted);

  Optional<SoftDeleteUser> findByIdAndIsDeleted(
      Long id, Integer isDeleted);
}

Test scenario

  1. Persist two users with isDeleted = 0
  2. Call
    existsByEmailIgnoreCaseAndIdNotAndIsDeletedNot("USER@EXAMPLE.COM", otherId, 1)
  3. Call
    findByIdAndIsDeleted(activeId, 0)

Environment

  • Spring Boot: 4.0.x
  • Spring Data JPA: 4.0.2 (or current 4.x)
  • EclipseLink: 5.0.0-B13
  • JDK: 17
  • Database: H2 (in-memory); also reproduced with other databases

Workaround

Annotating repository methods with explicit JPQL using @Query avoids these failures.

Additional notes / possible direction

  • Hermes appears to reject JPQL with implicit select aliases (select o.id id).
  • EclipseLink 5 also seems to under-report positional parameters in some derived queries, leading to ?2 binding errors.

Links

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions