'Spring JPA Projection inside of Projection
i have following entities
A.class
@Entity
public class A {
List<B> listOfB;
//getters and setters
}
B.class
@Entity
public class B {
private long id;
private List<C> listOfC;
//getters and setters
}
C.class
@Entity
public class C {
long getId();
}
In some cases C.class is unnecessary. So I tried to ignore it at the query with projection;
AView.class
public interface AView {
List<BView> getB();
}
BView.class
public interface BView {
long getId();
}
The JSON Response looks fine, but the Hibernate Query log is showing the SELECT of class C. I read a custom query at solution. But the Problem is that the classes have too many fields.
Is it posible to ignore the select of c in the query without writing a custom Query?
Solution 1:[1]
This seemed like a FetchType related issue to me.
If you are providing the relations with spring data jpa annotations, You might consider using FetchType.LAZY.
Like : @ManyToMany(fetch = FetchType.LAZY)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ahmed Gad |
