0

以下に示すコードを理解しようとしています

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 ステートメントを使用するとどのように見えるか教えていただけますか?

4

2 に答える 2

1
    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

For the table name, use the value in @Table annotation of the entity, for the column name, use the @Column name value located on field or getter, for the column name used in join, use the value in the @JoinColumn annotation located near the @OneToMany or @ManyToOne annotation

于 2015-09-14T08:32:57.383 に答える
0

createAlias参加を追加します

何かのようなもの

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

次に、結合されたテーブルを使用して、WHERE セクションに条件を追加できます

于 2015-09-14T08:27:38.993 に答える