Skip to content

AOT Query escape chars #1833

@BoykoAlex

Description

@BoykoAlex

See the following repo class:

@Repository
public interface OfficeRepository extends JpaRepository<Office, Integer> {

    List<Office> findByNameContainingIgnoreCase(String name);

}

The implementation of the method is below. Note the query string:

  /**
   * AOT generated implementation of {@link OfficeRepository#findByNameContainingIgnoreCase(java.lang.String)}.
   */
  public List<Office> findByNameContainingIgnoreCase(String name) {
    String queryString = "SELECT o FROM Office o WHERE UPPER(o.name) LIKE UPPER(:name) ESCAPE '\\'";
    Query query = this.entityManager.createQuery(queryString);
    query.setParameter("name", "%%%s%%".formatted(name != null ? name.toUpperCase() : name));

    return (List<Office>) query.getResultList();
  }

Now if use the CodeLens to add a query annotation the escape char from \\ becomes \. See below:

    @Query("""
            SELECT o
            FROM Office o
            WHERE UPPER(o.name) LIKE UPPER(:name) ESCAPE '\'
            """)
    List<Office> findByNameContainingIgnoreCase(String name);

The produced query is invalid. The app fails to start with this query.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions