-
-
Notifications
You must be signed in to change notification settings - Fork 66
Add support for subquery modifiers (LIMIT/OFFSET) in Hibernate #1304
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
Add support for subquery modifiers (LIMIT/OFFSET) in Hibernate #1304
Conversation
This change enables the use of LIMIT and OFFSET modifiers within subqueries when using Hibernate as the JPA provider. This addressing the limitation where modifiers were previously ignored in subquery contexts. **Key changes:** * Add `isSubQueryModifiersSupported()` method to JPQLTemplates - Returns false by default (standard JPQL behavior) - Overridden in HQLTemplates to return true (Hibernate-specific) * Update JPQLSerializer to conditionally serialize subquery modifiers - Add LIMIT and OFFSET constants for serialization - Modify `visit(SubQueryExpression)` to handle modifiers based on template support - Preserve existing behavior for non-supporting providers * Comprehensive test coverage - Unit tests for template support methods across all JPA providers - Serializer tests for both JPQL and HQL templates - Tests for various subquery contexts (WHERE, SELECT, nested subqueries) - Edge cases with combined LIMIT and OFFSET usage **Compatibility:** - Maintains backward compatibility for all existing JPA providers - Only affects Hibernate users who explicitly use subquery modifiers - No breaking changes to existing APIs Fixes subquery modifier limitations in Hibernate environments while preserving standard JPQL compliance for other providers.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1304 +/- ##
=======================================
Coverage 0.00% 0.00%
=======================================
Files 812 837 +25
Lines 31138 31479 +341
Branches 3531 3544 +13
=======================================
- Misses 31138 31479 +341 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, but can you please add a test to the HibernateBase
, to test it for reals too.
- Test subquery with LIMIT and OFFSET in WHERE clause - Test subquery with LIMIT in SELECT clause - Test subquery with OFFSET only - Verify actual functionality - Validate correct result count and data ordering
Thanks for the feedback! I've added comprehensive integration tests to HibernateBase that verify the actual functionality of subquery modifiers with Hibernate execution. |
Description
This PR addresses a long-standing limitation in QueryDSL where LIMIT and OFFSET modifiers were ignored when used within subqueries. This change enables full subquery modifier support specifically for Hibernate users while maintaining backward compatibility and JPQL standard compliance for other JPA providers.
Related Issue: This resolves the subquery modifier limitation reported in querydsl/querydsl#3224
Problem Statement
Previously, when users applied
.limit()
or.offset()
to subqueries, modifiers were silently ignored during query serialization. This was particularly frustrating for Hibernate users since Hibernate 6.0+ natively supports LIMIT/OFFSET in subqueries, but QueryDSL wasn't utilizing this capability.Example of previous behavior:
Solution
This implementation introduces a template-based approach that allows JPA provider-specific handling of subquery modifiers:
🔧 Core Changes
📋 Supported Scenarios
Compatibility
✅ Backward Compatibility
🎯 Provider Support
Technical Implementation Details
The implementation uses a template-based approach to maintain provider neutrality:
This design ensures that: