Skip to content

Conversation

@Mouon
Copy link
Contributor

@Mouon Mouon commented Nov 5, 2025

👋 Description

Hello QueryDSL team, it’s been a while!
I'm Mouon (munhyunjune), the original contributor who previously implemented the SimpleDTOProjection feature.
At my company, we have been using this version in our internal QueryDSL-based project.

However, we found some limitations in real-world usage:

  • It lacked collection field support, which reduced its flexibility.
  • The class and method names were somewhat unclear and experimental.

To address these issues, I have refactored and finalized this feature as NameBasedProjection, making it an official, production-ready component.


🧩 Key Changes

  • Renamed SimpleDTOProjectionNameBasedProjection to clarify its purpose and align with QueryDSL’s naming style.

  • Added support for multiple entities in the projection constructor (EntityPathBase<?>... entities).

  • Improved constructor matching logic to handle parameter names and fallback gracefully to field order when compiled without -parameters.

  • Enhanced error handling for missing field/parameter mappings.

  • Added detailed Javadoc comments, especially for the binder() method, explaining:

    • The purpose and usage of the feature
    • Matching logic and fallback behavior
    • Limitations and precautions for DTO–entity mapping
  • Updated tests (NameBasedProjectionTest) to verify multiple-entity and collection field handling.


🧠 Feature Details

NameBasedProjection enables automatic mapping between DTOs and entities by matching field names, eliminating the need for explicit field-by-field projection definitions.
This reduces boilerplate and improves readability, especially when working with large DTOs.

Example Comparison

Before:

Projections.fields(
    AnimalDTO.class,
    animal.alive,
    animal.bodyWeight,
    animal.dateField,
    animal.id,
    animal.name,
    animal.toes,
    animal.weight
);

After:

NameBasedProjection.binder(AnimalDTO.class, animal)
    .newInstance(true, 65.5, new Date(), 1, "Lion", 4, 150);

The class automatically binds entity fields to matching DTO constructor parameters (by name),
with fallback support for unnamed parameters (arg0, arg1, …) based on field order.


🧪 Testing

  • Added and verified unit tests for both single and multiple-entity projections.
  • Confirmed consistent behavior between Projections.fields() and NameBasedProjection.
  • Tested DTOs containing collections (List/Set) to ensure compatibility.

🙏 Feedback Welcome

If there are any shortcomings or stylistic issues, I would be more than happy to receive feedback.
My goal is to have this feature officially merged so that we can use it in our production environment.
I believe this enhancement can help many developers reduce redundant projection code and make DTO binding much easier.

Thank you again for maintaining this great project and taking the time to review this PR! 🙏
Please let me know if I should make any adjustments.

@Mouon
Copy link
Contributor Author

Mouon commented Nov 5, 2025

All tests have passed successfully
However, I’d like to mention that there might still be some weak points in terms of conventions or naming consistency. I’ll continue refining it based on your feedback if needed.

I’m always learning a lot from you, @velo
honestly, you’ve been a real mentor and lifesaver for me in this project. Thank you so much for your guidance and patience! 🙏

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 0% with 59 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@a3b3115). Learn more about missing BASE report.
⚠️ Report is 11 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...a/com/querydsl/core/types/NameBasedProjection.java 0.00% 59 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             master   #1460   +/-   ##
========================================
  Coverage          ?   0.00%           
========================================
  Files             ?     838           
  Lines             ?   31795           
  Branches          ?    3622           
========================================
  Hits              ?       0           
  Misses            ?   31795           
  Partials          ?       0           
Flag Coverage Δ
cubrid 0.00% <0.00%> (?)
db2 0.00% <0.00%> (?)
embedded 0.00% <0.00%> (?)
examples 0.00% <0.00%> (?)
firebird 0.00% <0.00%> (?)
mongodb 0.00% <0.00%> (?)
mysql 0.00% <0.00%> (?)
oracle 0.00% <0.00%> (?)
postgresql 0.00% <0.00%> (?)
test 0.00% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@velo
Copy link
Member

velo commented Nov 5, 2025

a bit rough to review what changed

can you bring back the original names or reduce the delta a bit so git can match the files and I can look at what changed, not a whole file

@Mouon
Copy link
Contributor Author

Mouon commented Nov 6, 2025

a bit rough to review what changed

can you bring back the original names or reduce the delta a bit so git can match the files and I can look at what changed, not a whole file

Thanks for the feedback. I reverted the file/class names back to the original so git can match the file, and I tried to keep the diff as small as possible.

Because the behavior changed a bit (we now fallback when constructor parameter names are missing), I updated some method names to better reflect what they do now. If that’s too much for this round, I can rename them back as well.

After this is reviewed, would it be okay to rename the class to NameBasedProjection again so the name matches the actual functionality?

Thanks again!

@velo velo enabled auto-merge (squash) November 6, 2025 11:44
@velo
Copy link
Member

velo commented Nov 6, 2025

All good, I think all that is missing is code format and done

auto-merge was automatically disabled November 7, 2025 01:02

Head branch was pushed to by a user without write access

@velo velo enabled auto-merge (squash) November 7, 2025 01:03
@Mouon
Copy link
Contributor Author

Mouon commented Nov 7, 2025

All good, I think all that is missing is code format and done

Thank you so much for approving the changes!

After the approval, I reverted the class name back to NameBasedProjection, and tried to make sure the formatting matches the project style as closely as possible.
However, I think there might be an automated formatting tool in the project, and it seems like my local setup isn’t matching it perfectly.

Would you mind helping me adjust it to the correct format?
I’d really appreciate your guidance on how the formatting is handled in this repo.

@velo velo merged commit 7926140 into OpenFeign:master Nov 7, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants