-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support projections on query methods that take a dynamic query type (Specification or Querydsl Predicate) [DATAJPA-1033] #1378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Oliver Drotbohm commented There's currently a clean separation between query methods and dynamic queries using either Your I guess we could check the query method for that special case (like "It takes a well known dynamic query type like |
Sebastian Staudt commented I think the most valuable benefit would be to reuse more complicated specifications (e.g. with multiple joins) and be able have a projected view at the same time. As an example I switched various parts of an application to specification to restrict the view on objects based on user permissions or filters set in the application. This works great. The queries are efficient and the developer experience is fantastic. The code is much more readable and dynamic. Instead of defining dozens of query methods you can mix and match specifications on demand. Currently, it feels like choosing between optimized results (projections) and powerful queries (specifications) |
Sebastian Staudt commented Recently, I found a workaround for implementing this feature in a custom repository implementation (see Gist). The main problem here is that If a future step might incorporate code similar to mine into |
daniel r. commented hi, any updates on this? Best Regards, |
Marc Collin commented any update?
any complex dynamic search will pass by an custom repository implementation.... and no projection is possible |
sfwhite commented I'm also in support of this. We have a use case where we have complex search criteria built out in specifications, but we need a lightweight result object (projection). We currently have to map to the lightweight by hand, as there isn't a way to combine the two easily. I also found a similar github project referenced from a stackoverflow question. There's definitely demand for this enhancement |
Sergio Clares Martínez commented ??We have a use case where we have complex search criteria built out in specifications, but we need a lightweight result object (projection).?? Same here. Regards |
Morjoh commented Any news about this? @Query(value = "",@Query(value = "", countQuery = "", nativeQuery = true)
Page<ProfileProjection> findByXXX(Specification<ProfileProjection> spec, Pageable pageable); No exceptions, Specification is just being ignored without creating the "where" statement |
Christophe Maillard commented
Exactly. As I had to chose either/or, I've chosen specifications, but being able to project the results would be ()()(*) Any news about this? |
Mahesh commented Need above feature "Specifications with projections and pagination" very badly |
Hurelhuyag commented Any news? Any workaround? |
Warsic Dia commented I stumbled to this problem today. And I think it's a "must have" to be able to mix projection and specifications. in the meantime I found this github repository which could be a workaround. But I did not give it a try yet |
Matija Folnović commented Hello! This issue, together with other related issues ( DATAJPA-393, DATAJPA-51, DATAJPA-1189 ) have a total of ~109 votes. Just thisissue alone is 3rd in total votes. I'm aware you have limited resources and you need to somehow prioritize issues, but is there a way to prioritize this as it's cleary highly requested issue? :) Another clear indicator this is highly requested is workaround Github repository above, which at the moment has 69 stars. Thank you very much for all the hard work you do here! :) |
ziomill commented This improvement would be great! |
Bernhard Kern commented Yes, this improvedment would help us alot, is there any update in 2020. Thx! |
atg200 commented I would really love this feature as well. I have this use case all the time |
wirk commented We would appreciate if this feature could be considered as we have several use cases. Cheers |
Leonardo Terrão commented This improvement would be great for me too! I've many cases that need this feature. Thanks! |
liviu-c commented well, it's a basic feature for any listing with dynamic filter. of course, there is criteria api, but this feature would be more apropiate ... |
mhmdsalem1993 commented any updates on this feature ? |
this9is3me commented would really love to have this feature too! is there any update? |
lorenzodee commented Anyone have some time to review? Thanks in advance |
Jens Schauder commented lorenzodee I just had a quick look at your PR. Not in detail, just superficial the approach you have choosen. Your approach is to extend the But I find the original approach rather compelling even though Oliver Drotbohm argued against it some extend in the first comment: Start from query derivation and add I envision the following rules:
What does everybody else think? Apart for This might even make |
Jens Schauder commented We had a discussion in the team about this and there are some concerns, that with special handling of In general my concern was shared about the current proposal that duplicating the methods in Therefore an alternative was proposed to have one additional method in the
Let us know what you think |
Jens Schauder commented I'm personally not convinced that this reduces complexity compared to an extension of the query derivation approach. After all, it would create another way to specify projections, conversions and options. And it would be another (partial) DSL to configure queries. The one thing I really like about the proposal is that it creates a dedicated type for projections. That would help with issues where users want to use an actual class as argument to their queries |
Oliver Drotbohm commented The prototype I had locally a few years ago (which unfortunately got lost at some point) was basically just introducing overrides that took a A very compelling argument with that is that it would still contain the added complexity in the specification related APIs, which are – important reminder – a Spring Data JPA specific thing. Anything that suggests a model that overlaps with existing general query capabilities unfortunately has to justify how that affects the programming model for other stores and probably has a hard time doing that if it starts with a very store specific abstraction in the first place |
Jens Schauder commented After some more internal discussion we came up with the following plan: We'll demo a custom implementation of this and then take a look at the code to see if we can extract some kind of infrastructure that makes it easier to implement this kind of method. If this works out it would allow easy implementation of such methods, without the potential burden of supporting an ever grower complexity of interacting features |
i need this feature too. i search google to flow the problem it lead me here. |
Do we have any update on this. Is it a WIP yet ? Thank you. |
Any update on this please? |
I would happy to see this solution implemented in Spring too. :) |
Guys, since 3 years until now, i looking for this feature! |
almost 6 years passed since this issue opened guys, any update now? |
We desperately need this. |
This would be a really great feature. Would appreciate if Spring implements this |
Also make sure expressions like the following work: |
Another thumbs up from me for implementing this. We may consider stop using Specifications due to this. I have tried the workaround on Github: https://github.com/pramoth/specification-with-projection |
@mp911de can you update us on this please ? |
this case does not respect the UserDTO interface and returns the full User objects.is there any solution to this?
|
there is a solution for this Just replace Order model with ur model
|
Hi Spring team, I have worked around with projection and specification issue and thought the same as topic owner but no hope and I have come to another solution like this
which I think I accept it but there is an issue with this, when I called my api, Application log looks like this which turns out to be N + 1 problem rather than fetch join. I have tested the projection without spec and it created the join statement but |
Sebastian Staudt opened DATAJPA-1033 and commented
Currently there seems no (at least no obvious) way to mix projections and specifications.
A query method like the last above causes a
java.util.NoSuchElementException
insideorg.springframework.data.jpa.repository.query.CriteriaQueryParameterBinder#bind
during query. (Which may be another problem on its own.)Affects: 2.0 M1 (Kay), 1.11 RC1 (Ingalls), 1.10.6 (Hopper SR6)
Issue Links:
Referenced from: pull request #430
107 votes, 96 watchers
The text was updated successfully, but these errors were encountered: