I use JPA with Hibernate implementation. My question is probably basic for experienced hibernate users: what is the most efficient way to write queries based on Hibernate first level cache?
For example, I have entity A and entity B:
@Entity
class A{
private int ida;
private int x;
private String s;
@OneToMany(mappedBy = "ida", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<B> Bset;
}
@Entity
class B{
private int ida;
private String s2;
}
Suppose I have several flows that may happen in the same session:
- get
A.x - get the whole
Aentity - check if
AcontainsBwiths2="...";
For every one of these queries I can
- write a specific query that gets
A.x/Bbyidaands2or - suppose that Hibernate saves cache and always get
Aobject, orA.Bset()and then java loops to get the neededBinsideBset()
What is the most efficient way?
thank you