Dyorgio
Dyorgio

Reputation: 1304

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.

Upvotes: 8

Views: 5202

Answers (2)

Holger Jannasch
Holger Jannasch

Reputation: 1

Solution using lastest QueryDSL API 5.x

Expressions.stringTemplate("collate({0} as binary_ci)", someStringPath)

Using Hibernate Query Language collate() function https://docs.jboss.org/hibernate/orm/current/querylanguage/html_single/Hibernate_Query_Language.html

Upvotes: 0

Robert Bain
Robert Bain

Reputation: 9586

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);

Upvotes: 8

Related Questions