You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "matrei (via GitHub)" <gi...@apache.org> on 2026/10/04 08:43:20 UTC

[PR] Return joined entities and native query entities from Hibernate 7 HQL and SQL queries [grails-core]

matrei opened a new pull request, #16506:
URL: https://github.com/apache/grails-core/pull/16506

   ## Description
   
   Hibernate 7 queries are typed, so the HQL methods of GORM for Hibernate 7 choose a result type for each query from its select clause (`HqlQueryContext.getTarget`). Two cases chose the wrong one.
   
   ### A single select item other than the root alias
   
   For a select clause with one item that has no `.` and is not an aggregate, the query was run with the queried entity's class as the result type. That is right for `select b from Book b`, but not for a joined alias or a function:
   
   ```groovy
   Book.executeQuery('select distinct a from Book b join b.author a')
   // QueryTypeMismatchException: Incorrect query result type: query produces 'Author' but type 'Book' was given
   ```
   
   The entity class is now used only when the item is the root alias, which includes the entity name in an unaliased query. Any other single item, such as a joined alias, `current_date` or `new map(...)` without a qualified property, uses `Object`, so Hibernate returns the value as it is.
   
   ### Native queries without an alias
   
   `findWithSql` and `findAllWithSql` run native SQL and return entities. When the SQL had no table alias, its select clause was normalized from `*` to `e.*`. The `.` then made the query run as a scalar query, so `findAllWithSql('select * from book order by title')` returned rows of column values instead of `Book` instances.
   
   A native query now always returns the entity, as GORM for Hibernate 5 does by adding the entity to every native query.
   
   ### Tests
   
   - New `HqlSelectResultTypeSpec` exercises the public API:
     - `executeQuery` with a joined alias, with and without parameters, returns the joined entities
     - selecting the root alias, a property or an association still returns entities or values
     - `findAllWithSql` with unaliased `select *` returns entities
   
     Without the change, the joined-alias and native cases fail.
   - `HqlQueryContextSpec`:
     - `getTarget` cases for the root alias (aliased, with `as`, unaliased, with joins), a joined alias, a theta join, `current_date` and `new map(...)`
     - a native-query case for `prepare`
     - the `isPropertyProjection` feature is replaced by these cases, since the method is gone
   
   All tests of `:grails-data-hibernate7-core:test` pass, and so do `checkstyleMain` and `codenarcMain`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Return joined entities and native query entities from Hibernate 7 HQL and SQL queries [grails-core]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16506:
URL: https://github.com/apache/grails-core/pull/16506#issuecomment-5979047413

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 03c9e6569496f3938b8d64312b5a770e49484d1e
   ▶️ Tests:  94372 executed
   ⚪️ Checks: 85/85 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Return joined entities and native query entities from Hibernate 7 HQL and SQL queries [grails-core]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #16506:
URL: https://github.com/apache/grails-core/pull/16506#issuecomment-5978573301

   ## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/16506?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 59.4030%. Comparing base ([`620d549`](https://app.codecov.io/gh/apache/grails-core/commit/620d549caaf29f053bd2a855583fe8a4d89af74c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`03c9e65`](https://app.codecov.io/gh/apache/grails-core/commit/03c9e6569496f3938b8d64312b5a770e49484d1e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/grails-core/pull/16506/graphs/tree.svg?width=650&height=150&src=pr&token=qJrryhpk7u&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/grails-core/pull/16506?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##                8.0.x     #16506        +/-   ##
   ==================================================
   - Coverage     59.4048%   59.4030%   -0.0018%     
   + Complexity      24859      24858         -1     
   ==================================================
     Files            2171       2171                
     Lines          108237     108237                
     Branches        19744      19744                
   ==================================================
   - Hits            64298      64296         -2     
   - Misses          35001      35003         +2     
     Partials         8938       8938                
   ```
   [see 4 files with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/16506/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Return joined entities and native query entities from Hibernate 7 HQL and SQL queries [grails-core]

Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty merged PR #16506:
URL: https://github.com/apache/grails-core/pull/16506


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org