Top Description Fields Methods
jakarta.data.repository

public @Interface Repository

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

Annotates a repository interface to 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 SET price = price - (price * ?1) WHERE price * ?1 <= ?2")
    int putOnSale(float rateOfDiscount, float maxDiscount);

    ...
}
@Inject
Products products;

...
found = products.findByNameLike("%Printer%");
numUpdated = products.putOnSale(0.15f, 20.0f);

The module Javadoc provides an overview of Jakarta Data.

Field Summary

Modifier and TypeField and Description
public static final String
ANY_PROVIDER

Value for the Repository#provider() 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.

public static final String
DEFAULT_DATA_STORE

Value for the Repository#dataStore() attribute that indicates to use a default data store.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the name of a data store or DEFAULT_DATA_STORE.
dataStore
()

Optionally indicates the data store to use for the repository.

public String

Returns:

the name of a Jakarta Data provider or ANY_PROVIDER.
provider
()

Restricts the repository implementation to that of a specific Jakarta Data provider.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Field Detail

ANY_PROVIDERback to summary
public static final String ANY_PROVIDER

Value for the Repository#provider() 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.

DEFAULT_DATA_STOREback to summary
public static final String DEFAULT_DATA_STORE

Value for the Repository#dataStore() attribute that indicates to use a default data store.

When running in a Jakarta EE profile or platform and the entity annotations indicate a relational database, the default data store is the Jakarta EE default data source, java:comp/DefaultDataSource. Otherwise, the default data store is determined by the Jakarta Data provider.

The default data store might require additional vendor-specific configuration, depending on the vendor.

Method Detail

dataStoreback to summary
public String dataStore()

Optionally indicates the data store to use for the repository.

Precedence for interpreting the dataStore value is as follows, from highest precedence to lowest precedence.

  • If running in an environment where Jakarta Config is available and the value is found in Jakarta Config, an error is raised. Interoperability with Jakarta Config is reserved for future versions of Jakarta Data.
  • If running in a Jakarta EE profile or platform and the entity annotations indicate a relational database and the value begins with java: and matches the name of a jakarta.annotation.sql.DataSourceDefinition, the JNDI name of a data source, or a resource reference to a data source, then the corresponding javax.sql.DataSource is used as the data store. If the same conditions are met but the value matches a persistence unit reference, then the corresponding jakarta.persistence.PersistenceUnit is used as the data store.
  • Otherwise, the value serves as an identifier linking to vendor-specific configuration for the Jakarta Data provider to interpret in a vendor-specific way. Refer to the documentation of the Jakarta Data provider.

The default value of this attribute is DEFAULT_DATA_STORE.

Returns:String

the name of a data store or DEFAULT_DATA_STORE.

providerback to summary
public String provider()

Restricts 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 Repository annotations 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:String

the name of a Jakarta Data provider or ANY_PROVIDER.