Spring数据规范加入并按查询分组

时间:2019-05-30 16:28:22

标签: spring spring-boot spring-data-jpa

我有一个课,需要从数据库获取每个设置的最高版本。

@Table(name = "SETTINGS")
class SettingsEntity {

 String id;
 int version;
 String name;
 boolean is_deleted;

}

以下是我要执行的查询

Select s.id, s.version, s.name from SETTINGS as s
join (select id, max(version) as version from SETTINGS  group by id) as r
on(s.id = r.id and s.version = r.version) where s.is_deleted = false;

我有一个需要运行此查询的规范。

public class SettingsQuerySpec implements Specification<SettingsEntity>
{

    @Override
    public Predicate toPredicate(Root<SettingsEntity> settingsEntityRoot, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder)
    {
      // how to write the query in specification.

    }

}

0 个答案:

没有答案