Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 900
Dyorgio Avatar asked Apr 14 '15 18:04

Dyorgio


1 Answers

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);
like image 191
Robert Bain Avatar answered Sep 30 '22 17:09

Robert Bain