20 Temmuz 2018 Cuma

JPA @NamedEntityGraph Anotasyonu

Giriş
Şu satırı dahil ederiz
import javax.persistence NamedEntityGraph;
import org.springframework.data.jpa.repository.EntityGraph;
JPA 2.1 ile geliyor. Açıklaması şöyle. Özellikle LAZY ilişki varsa bu anotasyon EAGER sonuçlar elde edilebilir. N + 1 Select problemini çözebilir.
Lazy loading of relations between entities is a common pattern to load only the required information from the database and to improve the performance of the application. While this is a great feature as long as the related entities are not required, it creates additional load when the relations need to be initialized. There are multiple ways to initialize these lazy relations and using Named Entity Graphs is one of the better ones.
The annotations @NamedEntityGraph, @NamedAttributeNode and @NamedSubGraph allow us to define a graph of entities that will be loaded from the database.
SpringData kullanıyorsak Spring'e ait @EntityGraph anotasyonu da kullanılabilir.



Hiç yorum yok:

Yorum Gönder