Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
@Entity public class Foo { int v1; int v2; @ManyToOne Bar bar; } Query query = EntityManager.createQuery("select foo from Foo");
上記のクエリは (s) 個のオブジェクトを返しますFooが、load(s)個のbarオブジェクトも返します。バー オブジェクトの読み込みを防ぐにはどうすればよいですか?
Foo
bar
デフォルトでは、多対一の関係は熱心です。遅延フェッチが優先される場合は、次のように実行できます。
@ManyToOne (fetch=FetchType.LAZY)
FetchType.LAZY はプロバイダーへの単なるヒントであり、JPA 2.0 仕様によると、FetchType.LAZY を持つ属性はロードされている場合とロードされていない場合があります。したがって、すべての JPA 実装で遅延が保証されるわけではありません。Hibernate では機能します。