Module jakarta.data

Interface CrudRepository<T,K>

Type Parameters:
T - the type of the primary entity class of the repository.
K - the type of the unique identifier field of property of the primary entity.
All Superinterfaces:
BasicRepository<T,K>, DataRepository<T,K>

public interface CrudRepository<T,K> extends BasicRepository<T,K>

A built-in repository supertype for performing Create, Read, Update, and Delete (CRUD) operations.

This repository extends the BasicRepository interface, adding insert(S) and update(S) operations in addition to basic retrieval and deletion. This interface combines the Data Access Object (DAO) aspect with the repository pattern, offering a versatile and complete solution for managing persistent entities within Java applications.

The type parameters of CrudRepository<T,K> capture the primary entity type (T) for the repository and the type of the unique identifier attribute (K) of the primary entity type.

The primary entity type is used for repository methods, such as countBy... and deleteBy..., which do not explicitly specify an entity type.

Example entity:

 @Entity
 public class Cars {
     @Id
     public long vin;
     public String make;
     public String model;
     public int year;
     ...
 }
 

Example repository:

 @Repository
 public interface Cars extends CrudRepository<Car, Long> {

     List<Car> findByMakeAndModel(String make, String model, Sort<?>... sorts);

     ...
 }
 

Example usage:

 @Inject
 Cars cars;

 ...

 Car car1 = ...
 car1 = cars.insert(car1);

 List<Car> found = findByMakeAndModel(car1.make,
                                      car1.model,
                                      Sort.desc("year"),
                                      Sort.asc("vin"));
 

The module Javadoc provides an overview of Jakarta Data.

See Also: