I have two @OneToOne entities:
...
public class A {
...
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "b_id", nullable = false)
private B b;
...
}
...
public class B {
...
@OneToOne(fetch = FetchType.LAZY, mappedBy = "b", cascade = CascadeType.ALL, orphanRemoval = true)
private A a;
...
}
and I'm using spring data JPA JpaRepository<T, ID> to fetch all entities (findAll() method).
Is it possible to fetch all B entities with lazily initialized A property (to not fetch A property whenever I fetch all B entities? If not, is it possible to avoid N+1 select in this case?
Edit: My question is different from How can I make a JPA OneToOne relation lazy How can I make a JPA OneToOne relation lazy because mine is other way around, I want to fetch parent entities and/or to avoid N+1 select while fetching it.