0

私はドメインオブジェクトを持っています

@Entity
@Table (name = "vw_t_bucket")
public class TBucket {

....

@ManyToOne (cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, targetEntity = Prd.class)
      @JoinColumns({
          @JoinColumn(name = "key", referencedColumnName="key"),
          @JoinColumn(name = "cdate", referencedColumnName="cdate")
      })
      public IPrd getPrd() {
        return prd;
      }
....

      @ManyToOne (cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, targetEntity = Acct.class)
      @JoinColumn (name = "acct", nullable = false)
      public IAcct getAcct() {
            return acct;
      }

}

@Entity
@Table (name = "product")
public class Prd implements IPrd {
...
}


@Entity
@Table (name = "vw_acct")
public class Acct implements IAcct {
...
}

ご覧のとおり、TBucket はビューであり、テーブル ( product ) と別のビュー ( vw_acct) に結合されています。

ビューとテーブルの両方を結合するとパフォーマンスが低下し、ビューをテーブルに変更する必要があるとデータベースから言われました。

ただし、ビュー自体は複数のテーブルからの結合で構成されています。

私のリードは、結合 SQL をアノテーションに直接入れることができる解決策があるかどうか疑問に思っていました。私は、ドメイン オブジェクトとのマッピングにのみテーブル/ビューを使用できると彼に言いました。

この問題に対する可能な解決策があるかどうか疑問に思っています。

4

1 に答える 1

0

If you do not update this entity, you can use the org.hibernate.annotations.Subselect annotation to name exact SQL to use. It was actually developed (well on the HBM XML mapping side) a long time ago as a stand-in for views on databases that did not support views. But, like I mentioned, it is read-only.

If you need to update, then you would need to use the org.hibernate.annotations.Loader, org.hibernate.annotations.SQLInsert, org.hibernate.annotations.SQLUpdate and org.hibernate.annotations.SQLDelete annotations to fully map the enity.

Yet, another option (depending on exact nature of the DB view) is to map that joins as SecondaryTables.

于 2012-06-05T16:55:52.967 に答える