Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (56 sloc) 1.66 KB
<html>
<head>
<title>FetchGroup | Query | Ebean</title>
<meta name="layout" content="_layout/docs_query_select.html"/>
<meta name="bread2" content="FetchGroup" href="/docs/query/fetchgroup"/>
<#assign fetchgroup= "true">
</head>
<body>
<h2>FetchGroup</h2>
<p>
As an alternative to <em>select</em> and <em>fetch</em> we can use <em>FetchGroup</em> to specify what part of
the object graph to fetch.
</p>
<p>
We can use <em>FetchGroup</em> with both query beans and standard queries.
</p>
<p>
FetchGroups provide a clean way to separate the definition of "what part of the object graph to load" (query tuning)
from the definition of the query predicates (query business logic).
</p>
<p>
A FetchGroup is immutable, most often declared as a <code>static final</code> and can be combined to make other
FetchGroups.
</p>
<h4>e.g. Just top level select properties</h4>
```java
// immutable and threadsafe
static final FetchGroup<|Customer> fetch =
FetchGroup.of(Customer.class, "name, version, whenCreated"); // root level properties
...
List<|Customer> customers =
new QCustomer()
.select(fetch)
.name.istartsWith("Rob")
.findList();
```
<p>&nbsp;</p>
<h4>e.g. select and fetch properties</h4>
```java
// immutable and threadsafe
static final FetchGroup<|Customer> fetch =
FetchGroup.of(Customer.class)
.select("name, status") // root level properties
.fetch("contacts", "email") // associated bean properties
.build();
...
List<|Customer> customers =
new QCustomer()
.select(fetch)
.name.istartsWith("Rob")
.findList();
```
<@next "FilterMany" "/docs/query/filterMany"/>
<@edit "/docs/query/fetchgroup"/>
</body>
</html>
You can’t perform that action at this time.