Top Description Fields Methods
jakarta.data.repository

public @Interface By

extends Annotation
Annotations
@Retention:RUNTIME
@Target:PARAMETER
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target

Annotates a parameter of a repository method, specifying a mapping to a persistent field:

Arguments to the annotated parameter are compared to values of the mapped persistent field.

The field name may be a compound name like address.city.

For example, for a Person entity with attributes ssn, firstName, lastName, and address we might have:

@Repository
public interface People {

    @Find
    Person findById(@By(ID) String id); // maps to Person.ssn

    @Find
    List<Person> findNamed(@By("firstName") String first,
                           @By("lastName") String last);

    @Find
    Person findByCity(@By("address.city") String city);
}

The By annotation is unnecessary when the method parameter name matches the entity attribute name and the application is compiled with the -parameters compiler option that makes parameter names available at runtime.

Thus, when this compiler option is enabled, the previous example may be written without the use of By:

@Repository
public interface People {

    @Find
    Person findById(String ssn);

    @Find
    List<Person> findNamed(String firstName,
                           String lastname);

    @Find
    Person findByCity(String address_city);
}

Field Summary

Modifier and TypeField and Description
public static final String
ID

The special value which indicates the unique identifier field or property.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the persistent field name, or id(this) to indicate the unique identifier field.
value
()

The name of the persistent field mapped by the annotated parameter, or id(this) to indicate the unique identifier field or property of the entity.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Field Detail

IDback to summary
public static final String ID

The special value which indicates the unique identifier field or property. The annotation By(ID) maps a parameter to the identifier.

Note that id(this) is the expression in JPQL for the unique identifier of an entity with an implicit identification variable.

Method Detail

valueback to summary
public String value()

The name of the persistent field mapped by the annotated parameter, or id(this) to indicate the unique identifier field or property of the entity.

Returns:String

the persistent field name, or id(this) to indicate the unique identifier field.