生成的查询具有空字段

时间:2016-01-15 03:48:22

标签: hibernate jpa spring-data-jpa jpql

我使用spring-data-jpa和hibernate实现。

我有一份包含租金清单的保释金。

    @OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY, mappedBy = "bail")
    private List<Rent> rents;

租金可以多付。

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "rent")
    @OrderBy
    private List<RoomPayment> roomPaymentList;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "bail_id")
    private Bail bail;

所以我试图获得付款不全或没有付款的租金

select r from Rent r Join r.bail.lodger l where r.unpaidBalance > 0 or r.roomPaymentList is null order by r.rentId

Hibernate将此查询转换为

select
        rent0_.rent_id as rent_id1_33_,
        rent0_.bail_id as bail_id5_33_,
        rent0_.from_date as from_dat2_33_,
        rent0_.to_date as to_date3_33_,
        rent0_.unpaid_balance as unpaid_b4_33_ 
    from
        rent rent0_ 
    inner join
        bail bail1_ 
            on rent0_.bail_id=bail1_.bail_id 
    inner join
        lodger lodger2_ 
            on bail1_.lodger_id=lodger2_.lodger_id cross 
    join
        room_payment roompaymen3_ 
    where
        rent0_.rent_id=roompaymen3_.rent_id 
        and (
            rent0_.unpaid_balance>0 
            or . is null
        ) 
    order by
        rent0_.rent_id

或者是null ...那里缺少某些东西

1 个答案:

答案 0 :(得分:0)

列表不能为空。它可以是空的:

or r.roomPaymentList is empty