springdata找到top和复合键id

时间:2018-03-29 09:16:12

标签: java spring-data dsl

您好我正在尝试查询以选择我的实体:

  • 获取对复合ID的一个属性有限制的实体
  • 并限制复合id的第二个属性(获取Top(max))

这是我的Lot实体

@EmbeddedId
@AttributeOverrides({ @AttributeOverride(name = "idLot", column = @Column(name = "id_lot", nullable = false)),
@AttributeOverride(name = "versionLot", column = @Column(name = "version_lot", nullable = false, length = 10)) })
public LotId getId() {
        return this.id;
}
    ...

复合ID

@Embeddable
public class LotId implements java.io.Serializable {

    private int idLot;
    private int versionLot;
...

和我的查询

public List<Lot> findTopById_VersionLotAndId_IdLot(@Param("identifiant") int idLot);

给了我

Caused by: java.lang.IllegalArgumentException: No parameter available for part id SIMPLE_PROPERTY (1): [Is, Equals] NEVER.

1 个答案:

答案 0 :(得分:0)

这样做了伎俩

Optional<Lot> findTopById_IdLotOrderById_VersionLotDesc(@Param("identifiant") int idIdLot);