I have gone thru some of the links for hibernate fetch strategies on net.One brief and concise link i liked is http://www.mkyong.com/hibernate/hibernate-fetching-strategies-examples/. We have four type of fetch strategies. these are :-
- fetch-”join” = Disable the lazy loading, always load all the collections and entities.
- fetch-”select” (default) = Lazy load all the collections and entities.
- batch-size=”N” = Fetching up to ‘N’ collections or entities, Not record.
- fetch-”subselect” = Group its collection into a sub select statement.
My first question which one of the above qualifies for eager or lazyloading fetch type?
To raise my queries about hibernate fetch strategies the i am considering below code snippet in my Department class
@OneToMany(mappedBy = "department", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@Fetch(value = FetchMode.SELECT)
@BatchSize(size = 10)
private Set<EmployeeData> employees = new HashSet<EmployeeData>();
As per my understanding As soon as i mention fetchtype as eager, i am left only with join fetch strategy but when i mention as fetchtype as lazyloading, i have other three options i.e select,batch-size and subselect.Agreed? Now if i look at code snippet in one my legacy project , it mentioned fetch type as eager and fetch strategy as select which contracdicts each other. Right?
Another query is i do not see batch-size option when i write FetchMode. and do control + space in eclipse though i see other three fetch strategies?