下面显示的条件代码的等效 mysql 语句是什么

What is the equivalent mysql statement of criteria code shown below

我正在尝试理解下面显示的代码

Criteria criteria = session.createCriteria(Payables.class);
            criteria.add(Restrictions.eq("companyId", companyId));

        criteria.createAlias("makePayment", "makePayment");

        if (creditorId != null) {
            criteria.createAlias("makePayment.creditor", "creditor");
            criteria.add(Restrictions.eq("creditor.id", creditorId));
        }

            criteria.add(Restrictions.eq("journalEntryId", journalEntryId));

我确实知道 createCriteria 的作用,但是添加 createAlias 确实让我感到困惑。我已经阅读了文档,但一切仍然很模糊。

你能告诉我上面的代码看起来如何使用 mysql 语句吗?

createAlias 添加加入

类似

...
FROM Payables p1
     JOIN Payment as p2 ON p2.paybles_id=p1.id
...

然后就可以使用加入的table在WHERE段添加条件

    Criteria criteria = session.createCriteria(Payables.class);
    // select * from Payables p;

    criteria.add(Restrictions.eq("companyId", companyId));
    // where p.companyId = :companyId

    criteria.createAlias("makePayment", "makePayment");
    // inner join Payement makePayment on makePayement.payables_id = p.id

    if (creditorId != null) {
        criteria.createAlias("makePayment.creditor", "creditor");
        // inner join Creditor c on c.payement_id = makePayement.id
        criteria.add(Restrictions.eq("creditor.id", creditorId));
        // where c.id = :creditorId
    }

    criteria.add(Restrictions.eq("journalEntryId", journalEntryId));
    // where p.journalEntryId = :journalEntryId

所以结果是:

    select * from Payables p
    inner join Payement makePayment on makePayement.payables_id = p.id
    inner join Creditor c on c.payement_id = makePayement.id
    where p.companyId = :companyId
    and c.id = :creditorId
    and p.journal_entry_id = :journalEntryId

对于table名称,使用实体@Table注释中的值,对于列名称,使用位于字段或getter上的@Column名称值,对于连接中使用的列名,使用位于@OneToMany 或@ManyToOne 注释附近的@JoinColumn 注释中的值