How to write a JPQL query for similar characters

I have a request to select similar objects from db.

Query query = entityManager.createQuery("select c from Case c where c.lastName = :lastName");

But I have a problem.

The "lastname" value for the object is "SAĞLAM" in the database, and the query parameter is "SAGLAM" or vice versa. Thus, the query does not give the entity.

The situation arises for C / Ç, S / Ş, G / Ğ, O / Ö, U / Ü, I / İ.

How can I solve this problem? Can I write a regex?

+4
source share
1 answer

In JPQL you cannot do this ... But with hibernate (HQL) you can do this :

select  upper(convert('This is a têst','US7ASCII')),
        upper(convert('THIS is A test','US7ASCII'))
from dual;

select  1 from dual 
where upper(convert('This is a têst','US7ASCII')) =
             upper(convert('THIS is A test','US7ASCII'))

JPA nativeQuery :

  • SELECT, ( SQL Server): SELECT e.name FROM Entity e WHERE e.name COLLATE Latin1_General_CI_AI LIKE 'têst' COLLATE Latin1_General_CI_AI
  • , SOUNDEX
  • regex

JPQL:

  • , , INSERT UPDATE . , .
+2

All Articles