Annotation Type DtoRef
Used with generated entity-to-DTO graph mapping (see query.mapTo(SomeDto.class)). The
DTO graph derived from a set of DTO types must form a DAG - generation fails at codegen time if
it doesn't. @DtoRef is the explicit escape hatch for an intentional back-reference,
e.g. a Contact DTO referencing its parent Customer by id only rather than
re-embedding the full CustomerDto (which would recreate the
Customer -> Contact -> Customer cycle):
public class ContactDto {
int id;
String firstName;
String lastName;
@DtoRef
Integer customerId; // id-only back-reference, no CustomerDto re-embedded
}
This is purely a compile-time / codegen-time hint - the DTO itself remains a plain, framework-free type with no runtime dependency on this annotation.
The association name (derived by stripping the Id suffix off the field/accessor name,
e.g. customerId -> customer) must name a real, fetchable Ebean relation (one
with a backing field) - if it's instead a computed/derived getter (e.g. a hand-written method
picking one entry out of a collection, with no backing field of its own), its own data
dependencies can't be inferred from the name alone, so requires() must explicitly name
the real entity paths that need to be fetched for it to execute safely without triggering a lazy
load:
@DtoRef(requires = "contacts")
Integer primaryContactId; // getPrimaryContact() derives its result from contacts
-
Optional Element Summary
Optional Elements
-
Element Details
-
requires
String[] requiresReal entity paths (dot-notation) that must be fetched to support a computed/derived association getter - required whenever the association name has no backing field, since its data dependencies can't otherwise be inferred. Ignored (and unnecessary) when the association names a real, fetchable relation.If the computed getter genuinely needs nothing extra fetched, set
requires = {}explicitly to confirm that - as opposed to omittingrequiresentirely, which is treated as "not yet considered" and fails the build with a clear compile error.- Default:
{}
-