spring-bootspring-data-jpaaccent-sensitive

How to ignore accents in Spring JPA findBy repository?


Lets say we have this repository:

public interface DeviceTypeRepository extends CrudRepository<DeviceType, Integer>, JpaSpecificationExecutor<DeviceType> {    
    public Iterable<DeviceType> findByNameContaining(String name);    
}

How to obtain the same results by ignoring when user mistypes accents ni search filter?

Examples: João | Joao | JOÃO, Marcio | Márcio etc.


Solution

  • There is no way to do that within Spring's built-in capabilities. You can consider using Elastic Search to do that, there is an article on this subject You Have an Accent.

    Another way is to not store accent letters in DB and perform mapping before executing SQL request or perform mapping on DB side using custom SQL function - but it's a too cumbersome and fragile solution.