jakartaee / data

Data-API
Apache License 2.0
105 stars 29 forks source link

Explore Specializations on Repositories #156

Closed otaviojava closed 1 year ago

otaviojava commented 1 year ago

As we talked about on this issue here, I would like to allow the spec to have in-depth details and expected behaviors on JPA; at the same point, don't assume that all database work as a relational database or have thousands of if exceptions at a single repository.

I propose creating a new specialization, a JPARepository, where we can do deep on behaviors for JPA.

Where:

graph TD;
    DataRepository-->CrudRepository;
    CrudRepository-->PageableRepository;
    PageableRepository-->JPARepository;

On this refactoring, there is no impact at the code level, but on documentation, where we need to move those particular relational details to a single place: JPARepository.

It does not mean that a JPA user cannot use a PageableRepository; a user can inject PageableRepository, and it will work. It is the Worker analogy, A lawyer is a worker, but I should not assume that all workers need a law degree.

@Inject
 PageableRepository repository; //can be a JPARepository implementation.

References:

:warning: I open for any name for this JPARepository.

dstepanov commented 1 year ago

I think JpaRepository as it is in Micronaut and Spring might not be the best. In JPA there is no such thing as save/update operations, and those methods being present there are very confusing.

There is a nice article about it https://vladmihalcea.com/best-spring-data-jparepository/

tandraschko commented 1 year ago

I just wondering: should it even be "JPA" anymore? Same like JSF, its now just Jakarta Faces.

KyleAure commented 1 year ago

Correct, JPA is an Oracle copyright.
I also don't see the benefit of defining a Jakarta Persistence exclusive repository pattern in the Jakarta Data specification. The only thing this would accomplish would be to cause confusion and make it so users assume they can only use Persistence Entities with this bespoke repository when they can use it with any of the repository interfaces.