整理有关 QueryDSL-JPA 的提示 [英] Collate hint on QueryDSL- JPA

查看:52
本文介绍了整理有关 QueryDSL-JPA 的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用 QueryDSL 执行它?(粗体部分):

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

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

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

我正在将 JPA 与 hibernate 结合使用.

I am using JPA with hibernate.

推荐答案

您可以使用addFlag(QueryFlag.Position position, String flag) 方法,记录在此处.

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

针对你在评论中的问题,如果你需要一个支持多个谓词的解决方案,你可以使用BooleanTemplatecreate(String template, Object one) 方法,记录在 此处.

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

您的查询应该类似于:

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

这篇关于整理有关 QueryDSL-JPA 的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆