How to optimize a JPA request

I have three objects as follows:

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
}

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?

+5
source share
2 answers

. . , , -. , , . , A B, .

# 1 , ,

c EntityC c, c.entityb.entitya =: entitya

+3

, SQL-, , . . , , . SQL MySQL : ON USING Theta-style, , .

+2

All Articles