Annotation Interface Repository
Annotates a data repository interface that will be implemented by the container/runtime.
This class is a CDI bean-defining annotation when CDI is available.
Regardless of whether CDI or custom dependency injection is used, the
repository implementation must be made available to applications via the
jakarta.inject.Inject annotation.
For example,
@Repository
public interface Products extends DataRepository<Product, Long> {
@OrderBy("price")
List<Product> findByNameLike(String namePattern);
@Query("UPDATE Product o SET o.price = o.price - (o.price * ?1) WHERE o.price * ?1 <= ?2")
int putOnSale(float rateOfDiscount, float maxDiscount);
...
}
@Inject
Products products;
...
found = products.findByNameLike("%Printer%");
numUpdated = products.putOnSale(0.15f, 20.0f);
-
Optional Element Summary
Optional Elements -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringValue for theprovider()attribute that allows the use of any available Jakarta Data provider that supports the type of entity annotation that is present on the repository's entity class.static final StringValue for thedataStore()attribute that indicates that the Jakarta Data provider should choose a default data store to use.
-
Field Details
-
ANY_PROVIDER
Value for theprovider()attribute that allows the use of any available Jakarta Data provider that supports the type of entity annotation that is present on the repository's entity class.- See Also:
-
DEFAULT_DATA_STORE
Value for thedataStore()attribute that indicates that the Jakarta Data provider should choose a default data store to use. The default data store might require additional vendor-specific configuration, depending on the vendor.- See Also:
-
-
Element Details
-
dataStore
String dataStoreOptionally indicates the data store to use for the repository.
The Jakarta Data specification does not define a full configuration model, and relies upon the Jakarta Data providers to provide configuration. This value serves as an identifier linking to vendor-specific configuration for each Jakarta Data provider to interpret in a vendor-specific way.
For some Jakarta Data providers, this value could map directly to an identifier in vendor-specific configuration. For others, this value could map to a base configuration path that forms a configuration hierarchy, such as in MicroProfile Config, or possibly Jakarta Config in a future version of this specification. For providers backed by Jakarta Persistence, it might point to a
jakarta.annotation.sql.DataSourceDefinitionname or ajavax.sql.DataSourceJNDI name or resource reference, or other vendor-specific configuration.The default value of this attribute is
DEFAULT_DATA_STORE.- Returns:
- the name of a data store or
DEFAULT_DATA_STORE.
- Default:
""
-
provider
String providerRestricts the repository implementation to that of a specific Jakarta Data provider.
This is useful when multiple Jakarta Data providers support the same type of entity annotation, in which case the provider attribute clarifies which Jakarta Data provider must be used. Jakarta Data providers must ignore
Repositoryannotations that indicate a different provider's name as the provider.The default value of this attribute is
ANY_PROVIDER, allowing the use of any available Jakarta Data provider that supports the type of entity annotation that is present on the repository's entity class.- Returns:
- the name of a Jakarta Data provider or
ANY_PROVIDER.
- Default:
""
-