I'm using SpringBoot, when a repository is called for the AModel, the repository is executing queries for BModel, CModel and DModel even when I am not calling for either CModel or DModel. any idea why this is happening and how I can prevent it?
@Entity
public class AModel extends Model {
@OneToOne(fetch = FetchType.EAGER)
@JsonIgnore
private BModel;
}
@Entity
public class BModel extends Model {
@OneToOne(fetch = FetchType.LAZY)
private CModel;
@OneToOne(fetch = FetchType.LAZY)
private DModel;
}
@Query("select a from com.project.models.AModel a where a.id = :id")
@Override
Candidate findOne(@Param("id")Long id);
The reason here is that when the entity AModel includes entity BModel, which in turn includes CModel and DModel. It has to fetch CModel and DModel when the fetch for AModel is called, otherwise your queries won't be able to complete if the objects of CModel and DModel are not fetched for, and the entire purpose of making the fetchType as Eager for AModel will be gone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With