1

私の休止状態のエンティティは次のとおりです。

@Entity
@Table(name = "EditLocks")
public class EditLock extends AuditableEntity {

    /** The document that is checked out. */
    @OneToOne
    @JoinColumn(name = "documentId", nullable = false)
    private Document document;

ドキュメントは次のようになります。

public class Document extends AuditableEntity {
    /** Type of the document. */
    @ManyToOne
    @JoinColumn(name = "documentTypeId", nullable = false)
    private DocumentType documentType;

基本的に、私が書きたいクエリは次のとおりです。

Select * from EditLocks el, Document docs, DocumentTypes dt where el.documentId = docs.id and docs.documentTypeId = dt.id and dt.id = 'xysz';

休止状態の基準 API を使用してこれを行うにはどうすればよいですか?

4

2 に答える 2

8

それはそれを行う必要があります:

Criteria criteria = getSession().createCriteria(EditLock.class);
criteria.createAlias( "document", "document" );
criteria.createAlias( "document.documentType", "documentType" );
criteria.add(Restrictions.eq("documenttype.id", "xyz");

クエリを実行するプロパティを持つオブジェクトに到達するには、エイリアスを追加する必要があります。

于 2010-08-02T23:54:16.547 に答える
0

したがって、DocumentType id='xyz'のドキュメントを持つEditLocksを取得しようとしているように見えます。DocumentとDocumentTypeには標準のHibernateマッピングがあると想定しています。

Criteria crit = getSession().createCriteria(EditLock.class);
crit.add(Restrictions.eq("document.documenttype.id", "xyz");

Hibernateは、私が思うに、結合を理解できるはずです。

于 2010-08-02T16:30:51.473 に答える