Declare and Inject a Repository

A repository declaration identifies its entity, identifier type, provider selection, and data store. Configure the selected store before deployment.

Declare a Persistence-Backed Repository

Use the weblogic provider for a supported Jakarta Persistence entity. This example selects the visible persistence unit CatalogPU.

import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.Repository;

@Repository(provider = "weblogic", dataStore = "CatalogPU")
public interface CatalogRepository
        extends BasicRepository<CatalogItem, Long> {
}

CatalogItem must be a supported Jakarta Persistence entity. The explicitly named persistence unit must exist.

Persistence-unit inference requires exactly one visible unit. WebLogic Server rejects ambiguous selection during deployment. Select the unit explicitly when more than one unit is visible.

You can omit the provider when selection is unambiguous. WebLogic Server’s persistence provider does not claim a repository that explicitly selects another provider.

Declare a NoSQL-Backed Repository

Use the Eclipse_JNoSQL provider for a supported Jakarta NoSQL entity. This example uses the local alias ordersStore.

import jakarta.data.repository.CrudRepository;
import jakarta.data.repository.Repository;

@Repository(provider = "Eclipse_JNoSQL", dataStore = "ordersStore")
public interface OrdersRepository
        extends CrudRepository<OrderDocument, String> {
}

The alias requires a standard resource-reference declaration and matching WebLogic JNDI mapping in the same effective scope. The mapping selects a valid, locally targeted global descriptor.

You can omit the provider when selection is unambiguous. Omitting dataStore requires exactly one valid, locally targeted resource explicitly bound to the application and marked as a default. Explicit alias selection does not require the selected resource to be a default.

For descriptor examples and plan overrides, see Bind an Application to a NoSQL Resource in Administering NoSQL Resources for Oracle WebLogic Server.

Inject a Repository into a Component

Inject a repository into a CDI-managed component in its owning deployment. This example injects OrdersRepository into an application-scoped service.

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@ApplicationScoped
public class OrdersService {
    @Inject
    OrdersRepository orders;
}

WebLogic Server publishes an injectable repository after validating the applicable definition, metadata, and resource selection. Unsupported or ambiguous declarations fail deployment.