我有这个实体
@Entity
public class RentAmount {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long rentAmountId;
private BigDecimal unpaidBalance;
private BigDecimal cashAdvance;
private BigDecimal totalRentAmount;
private LocalDate paymentRentDueDate;
private LocalDate paymentDueDate;
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
@OrderBy
private Set<RoomPayment> roomPaymentList;
@OneToOne
private Lodger lodger;
}
我的查询
select r from RentAmount r Join fetch r.lodger l join fetch l.bailList b join fetch r.roomPaymentList p where r.paymentRentDueDate <= :date and b.paymentPeriod=:paymentPeriod order by r.rentAmountId
RoomPaymentList 可以非常大,我正在寻找一种方法来限制返回的记录数。
有没有办法限制 roomPaymentList 中值的数量?
最佳答案
如果我没理解错 - 您想要限制每个 RentAmount
的 RoomPaymentList
行数,但不限制结果集中的行数。如果是这样,那么在 JPA 中就没有这样的方式。但是您可以编写一些 native 查询或存储过程并将其限制在子查询等中(Example of such query for MS SQL)。
关于jpa - 限制来自连接的记录数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36019796/