我有以下三个实体:
public class EntityA
{
private Long id;
//Getters and setters
}
public class EntityB
{
private Long id;
private EntityA entitya;
//Getters and setters
}
public class EntityC
{
private Long id;
private BigDecimal amount;
private EntityB entityb;
//Getters and setters
}
现在,给定一个EntityA的实例,我想得到一个EntityC的列表。我目前有两种选择。不知道哪个更优化。选项包括:
1.
select c from EntityC c where c.entityb in (select b from EntityB b where b.entitya = :entitya)
2. 给EntityB添加一个新属性
private Set<EntityC> entityCCol;
@OneToMany(mappedBy="entityb")
public Set<EntityC> getEntityCCol()
{
return entityCCol;
}
select b from EntityB a join fetch a.entityCCol b
这两个查询中哪一个更容易和优化?