I have three objects as follows:
public class EntityA
{
private Long id;
}
public class EntityB
{
private Long id;
private EntityA entitya;
}
public class EntityC
{
private Long id;
private BigDecimal amount;
private EntityB entityb;
}
Now, given the EntityA instance, I want to get the EntityC list. I currently have two options. I do not know which one is more optimized. Possible options:
1.
select c from EntityC c where c.entityb in (select b from EntityB b where b.entitya = :entitya)
2. Add a new property to EntityB
private Set<EntityC> entityCCol;
@OneToMany(mappedBy="entityb")
public Set<EntityC> getEntityCCol()
{
return entityCCol;
}
select b from EntityB a join fetch a.entityCCol b
Which of these two queries is simpler and more optimized?
source
share