sqlhibernatequerydsl

Collate hint on QueryDSL- JPA


There is a way to execute it with QueryDSL? (bold part):

SELECT * FROM Venue WHERE Name Like '%cafe%' COLLATE Latin1_general_CI_AI

I am using JPA with hibernate.


Solution

  • You can use the addFlag(QueryFlag.Position position, String flag) method, documented here.

    Something similar to the following should do what you want:

    query.addFlag(QueryFlag.Position.END, "COLLATE Latin1_general_CI_AI");
    

    In response to your question in the comments, if you require a solution that supports more than one predicate, you could use BooleanTemplate's create(String template, Object one) method, documented here.

    Something similar to the following should do what you want:

    BooleanTemplate.create("{0} COLLATE Latin1_general_CI_AI", venue.name.like("%cafe%"));
    

    Your query should look something like:

    query
    .from(venue)
    .where(BooleanTemplate.create("{0} COLLATE Latin1_general_CI_AI", venue.name.like("%cafe%"))
    .and(BooleanTemplate.create("{0} COLLATE Latin1_general_CI_AI", venue.name2.like("%milk%"))))
    .list(venue.name, venue.name2);