'Adding COLLATE to Spring Data JPA Query
I have a simple JPA Repository with both derived and native queries. Now, I have to (or at least I want to) specify collation for a given query, something like:
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "select * from users u order by u.firstname collate :language", nativeQuery = true)
List<User> findAllUsersCollate(@Param("language") String language);
}
As far as I'm concerned, derived queries do not support collations.
The problem arises when I try to use parameters to specify the collation name. Using hard-coded collations
@Query(value = "select * from users u order by u.firstname collate hun", nativeQuery = true)
works fine, but not suitable.
Note: In the example, 'hun' is a custom collation name with hu_HU locale.
I think the problem is with parameter substitution. Is there a way to specify collation for a given query using one of Spring Data JPA Query Methods? If not, how can I create a query that accepts a collation parameter and translates into a valid SQL query?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
