/data

Data-API

Primary LanguageJavaApache License 2.0Apache-2.0

Jakarta Data

Introduction

The Jakarta Data specification provides an API for easier data access to various database types, such as relational and NoSQL. A Java developer can access those repositories in several ways, including composing custom query methods on a Repository interface.

Jakarta Data’s goal is to provide a familiar and consistent, Jakarta-based programming model for data access while still retaining the particular traits and strengths of the underlying data store.

Repository

Jakarta Data provides repository abstractions designed to streamline the development of data access layers for various persistent stores, eliminating the need for extensive boilerplate code. These repository abstractions are broadly classified into two categories:

  • Built-in Repository Interfaces: Jakarta Data offers a hierarchy of built-in repository interfaces. The root of this hierarchy is the DataRepository interface, which includes several specialized interfaces like CrudRepository, BasicRepository, and more. These interfaces are designed to handle common data access operations and provide an extensible foundation for your data layer.

@Repository
public interface CarRepository extends BasicRepository<Car, Long> {

  List<Car> findByType(CarType type);

  Optional<Car> findByName(String name);

}
@Inject
CarRepository repository;
...
Car ferrari = Car.id(10L).name("Ferrari").type(CarType.SPORT);
repository.save(ferrari);
  • Custom Repository Interfaces: Besides the built-in repository interfaces, Jakarta Data enables you to create custom repository interfaces tailored to your domain requirements. These custom interfaces serve as a bridge between your domain’s semantics and the underlying database operations. With annotations like Insert, Update, Delete, and Save, you can define expressive and domain-specific repository methods that align seamlessly with your application’s needs.

@Repository
public interface Garage {

  @Insert
  Car park(Car car);

}
@Inject
Garage garage;
...
Car ferrari = Car.id(10L).name("Ferrari").type(CarType.SPORT);
repository.park(ferrari);

Whether you use built-in repository interfaces or create custom repositories, Jakarta Data empowers you to write more concise and expressive data access layers while reducing the need for boilerplate code.

Pagination

Jakarta Data also supports parameters to define pagination and sorting.

@Repository
public interface ProductRepository extends PageableRepository<Product, Long> {

 Page<Car> findByTypeOrderByName(CarType type, Pageable pageable);

}

Maven

To start to use Jakarta Data, add the API as a Maven dependency:

<dependency>
    <groupId>jakarta.data</groupId>
    <artifactId>jakarta.data-api</artifactId>
    <version>1.0.0-M1</version>
</dependency>

Testing Guideline

This project has a testing guideline that will help you understand Jakarta Data’s testing practices. Please take a look at the TESTING-GUIDELINE file.

Code of Conduct

This project is governed by the Eclipse Foundation Community Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to codeofconduct@eclipse.org.

Getting Help

Having trouble with Jakarta Data? We’d love to help!

Report Jakarta Data bugs at https://github.com/jakartaee/data/issues.

Building from Source

You don’t need to build from source to use the project, but you can do so with Maven and Java 17 or higher.

mvn clean install

Meetings