Spring JPA REST按嵌套属性排序 [英] Spring JPA REST sort by nested property

查看:64
本文介绍了Spring JPA REST按嵌套属性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有实体 MarketEvent.Market 实体有一列:

I have entity Market and Event. Market entity has a column:

@ManyToOne(fetch = FetchType.EAGER)
private Event event;

接下来我有一个存储库:

Next I have a repository:

public interface MarketRepository extends PagingAndSortingRepository<Market, Long> {
}

和投影:

@Projection(name="expanded", types={Market.class})
public interface ExpandedMarket {
    public String getName();
    public Event getEvent();
}

使用 REST 查询 /api/markets?projection=expanded&sort=name,asc 我成功地获得了具有按市场名称排序的嵌套事件属性的市场列表:

using REST query /api/markets?projection=expanded&sort=name,asc I get successfully the list of markets with nested event properties ordered by market's name:

{
    "_embedded" : {
        "markets" : [ {
            "name" : "Match Odds",
            "event" : {
                "id" : 1,
                "name" : "Watford vs Crystal Palace"
            },
            ...
        }, {
            "name" : "Match Odds",
            "event" : {
                "id" : 2,
                "name" : "Arsenal vs West Brom",
            },
            ...
        },
        ...
    }
}

但我需要的是获取按事件名称排序的市场列表,我尝试查询/api/markets?projection=expanded&sort=event.name,asc 但它没有用.我应该怎么做才能让它发挥作用?

But what I need is to get list of markets ordered by event's name, I tried the query /api/markets?projection=expanded&sort=event.name,asc but it didn't work. What should I do to make it work?

推荐答案

Just downgrade spring.data.‌ rest.webmvcHopper> 发布

Just downgrade spring.data.‌​rest.webmvc to Hopper release

<spring.data.jpa.version>1.10.10.RELEASE</spring.data.jpa.ve‌​rsion> 
<spring.data.‌​rest.webmvc.version>‌​2.5.10.RELEASE</spri‌​ng.data.rest.webmvc.‌​version>

projection=expanded&sort=event.name,asc // works
projection=expanded&sort=event_name,asc // this works too

感谢 @Alan Hay这个问题

在 Hopper 版本中按嵌套属性排序对我来说效果很好,但我确实在 Ingalls 版本的 RC 版本中遇到了以下错误.这被报告为已修复,

Ordering by nested properties works fine for me in the Hopper release but I did experience the following bug in an RC version of the Ingalls release.bug in an RC version of the Ingalls release. This is reported as being fixed,

  • jira 问题 - 按嵌入属性排序在 Ingalls RC1 中不再有效
  • 顺便说一句,我试过 v3.0.0.M3 报告说已修复但对我不起作用.

    BTW, I tried v3.0.0.M3 that reported that fixed but not working with me.

    这篇关于Spring JPA REST按嵌套属性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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