Collate hint on QueryDSL- JPA

拥有回忆 提交于 2021-01-27 07:14:46

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/29634657/collate-hint-on-querydsl-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!