We're updating the issue view to help you get more done. 

Sql Server: Special symbols in %like% are not escaped

Description

I use following method in Sprind Data JPA + hibernate:

@Query("SELECT u FROM UserEntity u WHERE LOWER(u.loginName) LIKE ?1")
Iterable<UserEntity> findAllUsersByNameLike(String likePattern);

and pass "%[08" as a parameter.

In result I have different responses from Sql Server and from Oracle database.

Oracle behaves as expected and treat `[` as an ordinary symbol and returns user entities that end with `[08`.

However, Sql Server treat `[` as a special T-SQL symbol (see https://docs.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql) and returns user entities with login names that end with `0` or `8`.

That is not correct according to JPQL spec (http://docs.oracle.com/html/E13946_04/ejb3_langref.html#ejb3_langref_like) that states that `all other characters [except % and _] stand for themselves`. (same for HQL)

Environment

Sql Server

Status

Assignee

Unassigned

Reporter

Andrii Pitukh

Labels

Components

Affects versions

4.3.11

Priority

Major