spring-projects / spring-data-r2dbc

Provide support to increase developer productivity in Java when using Reactive Relational Database Connectivity. Uses familiar Spring concepts such as a DatabaseClient for core API usage and lightweight repository style data access.
Apache License 2.0
708 stars 133 forks source link

Support for Criteria equivalent based queries like JpaSpecificationExecutor #246

Open rcpacheco opened 4 years ago

rcpacheco commented 4 years ago

Support for Criteria equivalent funtionality to do queries like JpaSpecificationExecutor. Being a user of spring data jpa, we use a lot the Specification based queries to implement paging, sort, search and filter funtionality in our apps. Having a similar capability would make the migration to r2dbc easier.

guillaumelamirand commented 3 years ago

Hi,

I agree with this. How could use queries like JpaSpecificationExecutor with spring data r2dbc ? I tried to mix data jpa and data r2dbc only for pagination queries but the application won't start. Do you have an ETA for that feature ?

Thanks

mp911de commented 3 years ago

I'm not sure we want to introduce such a feature in the first place. R2dbcEntityTemplate exposes exactly what you're looking for. What's wrong with using R2dbcEntityTemplate.select(Query, Class)?

guillaumelamirand commented 3 years ago

Yes of course but from my point of view it is also the purpose of a Repository to offer those kind of features. First of all because it is easier to use and also it is how we already use it with standard JPA implementation.

Why don't you want to add such feature? How whould we with r2dbc repository manage pagination and search ?

mp911de commented 3 years ago

You can use Pageable and Sort with query derivation. Alternatively, you can use @Query to specify your query.

Again, what's wrong with using R2dbcEntityTemplate.select(Query, Class)?

guillaumelamirand commented 3 years ago

In fact we are not using Query but Predicate coming from a built Specification, not sure R2dbcEntityTemplate.select(Query, Class) can solve this.

mp911de commented 3 years ago

Note that Spring Data R2DBC doesn't use JPA API hence there's no support for javax.persistence.criteria.Predicate.

guillaumelamirand commented 3 years ago

Ok, that confirm what I suspected. Does it mean I cannot use criteria api with R2dbc?

mp911de commented 3 years ago

There's org.springframework.data.relational.core.query.Criteria which is obviously different from the JPA Criteria type. However, they work similar and I'd argue that org.springframework.data.relational.core.query.Criteria is simpler to use.

guillaumelamirand commented 3 years ago

We are building a complex specification from a search param given by user to request what he wants. He gives us sth like "/topics?search=type:toto AND channel.user?" and we transform that into a Speficiation used to request the db.

I will have a look if org.springframework.data.relational.core.query.Criteria can be used the same way. Thanks any way for helping.

rcpacheco commented 3 years ago

We have the same situation, using specs to filter data from grids makes our work more Easy.

guillaumelamirand commented 3 years ago

@mp911de Sorry for the delay. I did take the time today to look into R2dbcEntityTemplate, Query and Criteria but from what I understand query doesn't manage entities relationship (join, left join, etc) so how could I use it with a complex query joining multiple table ?

mp911de commented 3 years ago

That is generally true for Spring Data R2DBC, we don't support relationships yet.

guillaumelamirand commented 3 years ago

@mp911de ok . Is it something plan for future release?

encircled commented 3 years ago

Btw Hibernate introduced completable future reactive API via Vert.x driver (and I've implemented a criteria API over it https://github.com/encircled/Joiner with support of reactor mono/flux)

hantsy commented 2 years ago

Micronaut Data R2dbc has already supported JPA annotations(on entity and associations) and such an JPA Specification variant(for complex queries) in the R2dbc(and Kotlin Coroutines) directly. I remember I have filed similar issues to request these features in Spring Data Jdbc/R2dbc on Spring Data Relational, but rejected.

mp911de commented 2 years ago

JPA annotations have a very different semantic associated and a lot of these (e.g. @GeneratedValue, @OneToOne, and others) are not supported by Spring Data R2DBC. Supporting JPA annotations would send out a bold signal to users and we immediately need to manage expectations to reduce the supported set of features so that it does not make any sense to support JPA annotations in the first place.