jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

JPA Entity Filtering option does not work when using reactive option #14616

Closed aricooperman closed 1 year ago

aricooperman commented 3 years ago
Overview of the issue

If you select reactive = true and also try to enable filtering on any entities, those entities will not have any filtering code generated for them, or at least the API does not support it

Motivation for or Use Case

If you want to have entity filtering and reactive at same time

Reproduce the error

Enable filtering on any entity and turn reactive on

Related issues

None seen

Suggest a Fix

Unsure

JHipster Version(s)

7.0.1

JHipster configuration

JDL to quickly reproduce, Just toggle reactive on and off and check resulting generation

JDL definitions
application {
  config {
    applicationType monolith
    authenticationType jwt
    baseName reactivefilterbug
    buildTool gradle
    packageName com.foo.bar
    reactive true
  }

  entities *
}

entity A {
  a Boolean required
  b Integer required
  c String required
}

filter *
  
Entity configuration(s) entityName.json files generated in the .jhipster directory

Generated from JDL above

Browsers and Operating System

Should not be browser or platform related but testing on Fedora 33

smaestri commented 3 years ago

After some investigations, Jhipster uses Spring Data Specifications and JpaSpecificationExecutor for filtering in non-reactive mode, not yet supported in reactive mode, as indicated here. Some notes to reproduce the error manually with generator:

It should be possible to filter manually for now, will check this.

smaestri commented 3 years ago

After some deeper investigations, I seems possible to do filtering by using Query By Example r2dbc feature. An example can be seen here. However, this feature requires Spring Boot 2.5.0-RC1., not yet released, and so not part of Jhipster for now. But I think it is possible to start working on this feature, and release it when Spring Boot 2.5.0 will be integrated into JHipster. Any remark or suggestion are welcome!

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

Tcharl commented 2 years ago

Please go for it @smaestri !

DanielFran commented 2 years ago

@smaestri Can you confirm you are still available to contribute with a PR?

smaestri commented 2 years ago

Hi, yes I have some free time to work on it in the next weeks. I Keep you posted

dwarakaprasad commented 2 years ago

Full disclosure - I am new to this Reactive & Criteria part

Just out of curiosity, why not use the existing org.springframework.data.relational.core.sql. or org.springframework.data.relational.core.query. to implement this feature.

Based on this issue - referenced by @smaestri spring R2DBC does not support relationship, so why bring in Query By Example.

I feel that the existing EntityCriteria implementation can be reused and the org.springframework.data.relational.core.sql.Condition part could be built based on the search-criteria enabling the filtering option (I am hoping that the Condition/Criteria would support all the existing non-reactive filtering options - I can do some investigation if you guys think its an acceptable approach)

Did a little reading and found the following (reference), "Query by Example also has several limitations: No support for nested or grouped property constraints, such as firstname = ?0 or (firstname = ?1 and lastname = ?2). Only supports starts/contains/ends/regex matching for strings and exact matching for other property types."

dwarakaprasad commented 2 years ago

Based on my previous comment, here is a sample gateway application with two entities (Customer & Address) implementing entity filtering, everything is supported except,

  1. Distinct
  2. Filtering by relationship on the non-owning side (this can be implemented but a bit involved)

All the tests (unit & e2e) have passed.

Here are the list of files changed for this feature.

If you guys like this approach, i can build this feature into the generator.

dwarakaprasad commented 2 years ago

@smaestri @mraible @DanielFran, what do you guys think about this implementation, is it good enough for the generator. I can make the ConditionBuilder more generic. Things that need you comments,

  1. EntityCriteria moved into domain package (from seervice) - Currently the query is being built in EntityManager, which takes Condition as an input param. Conversion of entityCriteria to Condition needs access to Table (built inside repository), Column (built inside repository) & ColumnConverter (component available inside repository)
  2. No filtering support on the non owning side - This can be done but will need changes to the API
  3. No '/count' rest service endpoint - There is no count method available in the R2dbc repository interface (similar to JpaSpecificationExecutor). I can create a facade method to return just the count, but I am not sure if that will have any performance impact.
dwarakaprasad commented 1 year ago

bug bounty claim https://opencollective.com/generator-jhipster/expenses/160398