generator-jhipster
generator-jhipster copied to clipboard
JPA Entity Filtering option does not work when using reactive option
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
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:
- add an entity:
jhipster entity myentity
- link service. In generator : Do you want to use separate service class for your business logic? Yes, generate a separate service class
- enable filtering. In generator : Do you want to add filtering? Dynamic filtering for the entities with JPA Static metamodel
- in reactive mode, you have a warning during project generation to inform user filtering will not work : WARNING! Not compatible with jpaMetamodelFiltering, disabling
It should be possible to filter manually for now, will check this.
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!
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
Please go for it @smaestri !
@smaestri Can you confirm you are still available to contribute with a PR?
Hi, yes I have some free time to work on it in the next weeks. I Keep you posted
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."
Based on my previous comment, here is a sample gateway application with two entities (Customer & Address) implementing entity filtering, everything is supported except,
- Distinct
- 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.
@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,
- 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)
- No filtering support on the non owning side - This can be done but will need changes to the API
- 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.
bug bounty claim https://opencollective.com/generator-jhipster/expenses/160398