-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement Automatic DTO Mapping Feature... #3618
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
For the time being, you can already use constructor expressions in your query. Meanwhile, we have a similar ticket in the issue tracker with #3076 to rewrite String-based queries into Constructor expressions so that the underlying JPA provider instantiates your class through a constructor. That way, the constructed type maintains its integrity. In contrast, creating an empty object instance and populating its fields violates the principle of an integer object. At what state does the object become valid/usable and how do you even verify that state? This specific concern addresses a class of potential bugs that we can eliminate by not introducing partially populated objects. |
Hello, mp911de, Thank you for your comment! I agree that constructor expressions can currently be used. However, if an automatic DTO mapping feature is provided, we can add logic to verify that field names and types match, which would help prevent mapping failures. A key point here is that the default behavior should be to create objects through the constructor and fill all fields. This will help maintain the integrity of the object. Additionally, since there are already issues with partially populated objects being created in JPQL, I believe that an automatic DTO mapping feature could address this problem. If automatic mapping is implemented, users will be able to safely create objects using constructors that contain all fields of the DTO. In this regard, could the automatic DTO mapping feature contribute to solving existing problems? I would also like to express that my main goal is to learn from your valuable experience and knowledge, mp911de. (Instead of simply suggesting an opinion, my intention is more to gain insights from your expertise.) |
I think that is doable in the course of #3076
That's the goal of the mentioned ticket. Thanks for your response. Looking at your request and the thoughts behind it, I would close this ticket as duplicate of #3076. |
Implement Automatic DTO Mapping Feature
I am leaving an issue to learn from great people 🙏🏻 🙏🏻 🙏🏻
Issue
Implement Automatic DTO Mapping Feature
Description:
We need a feature to automatically convert entity lists obtained from @query into DTOs. The goal is to add logic that uses reflection to automatically map values from entity fields to DTO fields with the same names.
Objectives:
Implement a method for automatic mapping from entities to DTOs
Use reflection for field mapping Handle exceptions for mapping failures
Sample Code:
Benefits
Simplifies mapping process
Can be used with @query annotations, e.g.
Note for Reviewers
I'm new to this and would greatly appreciate any guidance or suggestions for improvement. Thank you for your time and expertise! 🙏🏻
The text was updated successfully, but these errors were encountered: