小编Rom*_*lov的帖子

如何按具有不同 JPA 规范的获取属性进行排序

我使用 Spring Boot 1.5.3.RELEASE,对我来说,不清楚如何按嵌套对象的属性进行排序distinctSpecifications原因如下:

引起:org.postgresql.util.PSQLException:错误:对于 SELECT DISTINCT,ORDER BY 表达式必须出现在选择列表中

Spring Data JPA 生成错误的查询。

让我们看一个小例子:

模型

@Data
@Entity
@Table(name = "vehicle")
public class Vehicle implements Serializable {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    @ManyToOne
    @JoinColumn(name = "vehicle_type_id")
    private VehicleType vehicleType;

    @ManyToOne
    @JoinColumn(name = "vehicle_brand_id")
    private VehicleBrand vehicleBrand;
}
Run Code Online (Sandbox Code Playgroud)

我们有Vehicle带有嵌套对象的类VehicleTypeVehicleBrand.

@Data
@Entity
@Table(name = "vehicle_brand")
public class VehicleBrand implements Serializable {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    @Column(name = …
Run Code Online (Sandbox Code Playgroud)

sorting jpa distinct criteria-api spring-data-jpa

7
推荐指数
1
解决办法
315
查看次数

标签 统计

criteria-api ×1

distinct ×1

jpa ×1

sorting ×1

spring-data-jpa ×1