@Retention(value=RUNTIME) @Target(value=FIELD) public @interface FetchPreference
Ebean automatically limits the number of SQL joins to ToMany relationships to avoid SQL cartesian product and to honor SQL first row / max rows limits. It does this by allowing the first ToMany relationship/path that has been defined on a query to be included in the main query as a join and then converting any remaining ToMany relationship/path to "query joins".
Without explicit use of @FetchPreference the first path that contains a
ToMany is included in the main query as a join.
Indicate to Ebean the preferred relationships to join to.
Prefer joins to 'participants' over 'messages'
@FetchPreference(1)
@OneToMany(mappedBy = "conversation")
List<Participation> participants;
@FetchPreference(2)
@OneToMany(mappedBy = "conversation")
List<Message> messages;
// Without @FetchPreference the first ToMany which
// is "messages" is joined and "participants" is
// query joined (executed as a secondary query)
Ebean.find(Conversation.class)
.fetch("messages") // <- first ToMany path Ebean sees
.fetch("participants") // <- second ToMany path Ebean sees
.findList();
| Modifier and Type | Required Element and Description |
|---|---|
int |
value
The fetch preference used - low value means higher preference.
|
public abstract int value
Copyright © 2019. All rights reserved.