I'm working on some personal project but i have a question about hibernate.
I have a class structure like this :
@Entity
public class User {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "fkIdCompanyUser")
private Company company = new Company();
}
But inside the company i have another join.
@Entity
public class Company {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "fkIdCompanyEstimateOption")
private EstimateOptions estimateOptions = new EstimateOptions();
}
Now i do a query to get the estimate options. But if i do it like this it loads lots of unnecessary stuff .
@RequestMapping(value = "/estimateoptions")
public EstimateOptions getCompanyEstimateOptions(@AuthenticationPrincipal Principal user) {
User getuser = userDao.findByEmail(user.getName());
EstimateOptions estimateOptions = getuser.getCompany().getEstimateOptions();
return estimateOptions;
}
is there a better approach for this ?