Fetch Method

When retrieving an entity from persistence, its associations and element collections that are declared as eager or in the query entity graph will be fetched. The method of fetching eager attributes can be JOIN or SELECT using @FetchMethod annotation. For example,

import com.cmobilecom.jpa.FetchMethod;
import com.cmobilecom.jpa.FetchMethodType;

public class Order {

	@OneToMany(cascade={CascadeType.ALL}, orphanRemoval=true, fetch= FetchType.LAZY,
			mappedBy="order", targetEntity=OrderItem.class)
	@FetchMethod(FetchMethodType.JOIN)  // join
	//@FetchMethod(FetchMethodType.SELECT) // select (default for plural)
	private List<OrderItem> orderItems;
The orderItems is declared as LAZY, but it will be eagerly fetched if it is specified in query entity graph, and its fetch method is JOIN in the same main query. If fetch method is SELECT, it will be fetched using another select query after the main query. The 2nd select query will fetch all the data associated with the attribute for all the entities fetched in the main query for better performance. An example of join and select fetche graph:
selection(entity) -- attribute(join fetch)  --- attribute(select fetch)
                          |                           |
                     attribute(select fetch)    attribute(select fetch)
                     attribute(join fetch)  --- attribute(join fetch)
By default, the fetch method is JOIN for embedded attributes and singular association attributes, and SELECT for plural attributes.