简体   繁体   English

如何设置属性排序,当我使用Jpa Example.of

[英]How to set property sort ,When i use Jpa Example.of

How to assign property sort to generated sql? 如何将属性排序分配给生成的SQL? thanks 谢谢

table has index , i want set index property is first in where 表具有索引,我要设置索引属性在哪里

Message condition = new Message();
condition.setReceiver(account);
condition.setChannel(channel);
condition.setState(MessageState.INITIAL);

return messageRepository.findAll(Example.of(condition),Sort.by("createTime").descending());

The Generated sql is : where 生成的sql是:where

message0_.channel=? 
and message0_.state=0 
and message0_.receiver=? 

I want: where 我要:在哪里

message0_.receiver=? 
and message0_.channel=0 
and message0_.state=?

There's no API available to order predicates, I'm afraid. 恐怕没有可用的API来订购谓词。 If you want this level of control over the generated query, you're better off using a native query instead. 如果要对生成的查询进行这种级别的控制,最好使用本机查询。

Why do you feel you need that, though? 但是为什么您觉得自己需要呢? Most query optimizers ignore the order of predicates, in most cases. 在大多数情况下,大多数查询优化器都会忽略谓词的顺序。 Did you actually EXPLAIN the version of the query generated by Spring Data to find that the index is not being used? 你真的EXPLAIN由Spring数据生成的查询的版本发现未使用的指标?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM