I have a one to many mapping among 2 entities, something like.
Code:
class Father{
//. . .
@OneToMany(mappedBy="father",
cascade=CascadeType.ALL,
fetch=FetchType.LAZY
)
private List<Son> sonsList= new ArrayList<Son>();
}
In my code I retrieve the father from the database:
Code:
Father father = // code to retrieve the father
then I iterate through the sons:
Code:
Iterator<Son> iterator = father.getSonsList().iterator();
while(iterator.hasNext()){
Son mySon = iterator.next();
}
Now: as soon as I "hit" the sons list all the sons are loaded from the database with a kind of "select *" from the DB.
Is it possible to force Hibernate to execute a query to retrieve only the next son for every "next()" I call in my code? (or for each father.getSonsList().get(<index>))?
thank you