Skip to content

Hibernate 7 Support#15530

Open
jdaugherty wants to merge 906 commits intospring-boot-4from
8.0.x-hibernate7
Open

Hibernate 7 Support#15530
jdaugherty wants to merge 906 commits intospring-boot-4from
8.0.x-hibernate7

Conversation

@jdaugherty
Copy link
Copy Markdown
Contributor

@jdaugherty jdaugherty commented Mar 23, 2026

I accidentally pushed to 8.0.x-hibernate7 instead of 8.0.x-hibernate7-bom. This caused #15510 to close as a result.

From that PR's todos:

Current Progress:

Fixing bad merges of the gradle plugin extraction
Fixing license headers
Fixing styling
Attempted merge of code styles
Running CI against hibernate 7 branch
Splitting boms into a hibernate5 & 7 bom (probably needs more work)

TODO:

docs need further updates
several functional tests were added for hibernate 5 and not copied to the hibernate 7 - @jamesfredley
we need to diff the hibernate 5 functional tests with hibernate 7 to see if any were subsequently changed - @jamesfredley
functional tests in hibernate 7 should use the hibernate 7 bom.
grails-datamapping-core changes need to be looked at closer; I might have merged these the wrong way. - @jamesfredley

I am opening this PR to track the status of Hibernate 7 merge to 8.x.

Some notes from previous meetings on the Hibernate 7 Upgrade:

  • HibernateQuery is the core class, GormDetachedCriteria is now inside of it & this class no longer uses an abstract builder pattern. This does mean we need an active connection to create a query.
  • HibernateCriteriaBuilder was changed to HibernateQuery - purpose was to build query components & run separately
  • Domain Binding was changed to no longer use a monolithic class. Now, "GrailsDomainBinder" is instead a thin wrapper around the root binder implementation.

borinquenkid and others added 30 commits March 1, 2026 12:35
…classes

The Spotless Apply commit reformatted these Java files using Google Java
Format (2-space indentation), which violated the project's Checkstyle
rules that require 4-space indentation.

Restore the 5 affected files to 4-space indentation and fix the off-by-one
space in HibernatePersistenceContextInterceptor.java line 107.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- gradle/code-style-config.gradle:
  - Remove Checkstyle plugin/config; add Spotless (palantirJavaFormat,
    4-space indent) with import ordering matching the former Checkstyle
    ImportOrderCheck groups (java|javax → groovy → jakarta → other →
    spring → grails → static last), removeUnusedImports,
    trimTrailingWhitespace, endWithNewline
  - Add PMD plugin globally alongside CodeNarc; backed by a new
    etc/config/pmd/pmd.xml ruleset (bestpractices, errorprone, security)
  - codeStyle task now runs: Spotless check + CodeNarc + PMD

- gradle.properties:
  - Replace checkstyleVersion with pmdVersion=6.55.0

- etc/config/pmd/pmd.xml:
  - New PMD ruleset (category/java/bestpractices, errorprone, security)

- grails-data-hibernate7/core/build.gradle:
  - Remove local pmd and spotless plugin declarations/config (now
    handled globally via code-style-config.gradle)
  - Apply code-style-config.gradle; keep SpotBugs local config

Note: run ./gradlew spotlessApply to reformat existing Java sources to
palantirJavaFormat before next code style check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts:
#	.github/workflows/codestyle.yml
#	gradle/docs-dependencies.gradle
#	grails-data-hibernate5/core/src/test/groovy/grails/gorm/specs/BasicCollectionInQuerySpec.groovy
#	grails-data-hibernate5/core/src/test/groovy/grails/gorm/specs/DetachedCriteriaJoinSpec.groovy
#	grails-data-hibernate5/core/src/test/groovy/grails/gorm/specs/DetachedCriteriaProjectionNullAssociationSpec.groovy
#	grails-data-hibernate5/core/src/test/groovy/grails/gorm/specs/WhereQueryBugFixSpec.groovy
#	grails-data-hibernate5/core/src/test/groovy/grails/gorm/specs/WhereQueryOldIssueVerificationSpec.groovy
#	grails-data-hibernate5/dbmigration/build.gradle
#	grails-datamapping-core/src/main/groovy/grails/gorm/DetachedCriteria.groovy
#	grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/finders/CountByFinder.java
…ked as pending since GORM core is not for production
  I fixed two major initialization errors in HibernateDatastore.java that were breaking the multi-datasource TCK tests:
   * Broken Infinite Recursion: Introduced a private isChild flag and constructor to prevent child datastores from recursively iterating through connection sources. This resolved the StackOverflowError
     during multi-datasource setup.
   * Fixed ClassCastException: Updated the bytecodeProvider initialization to safely handle cases where the factory is not a HibernateConnectionSourceFactory (common in child datastores using
     SingletonConnectionSources).
   * Verification: Ran CrossLayerMultiDataSourceSpec, and all 5 tests passed.
### 1. Spring ORM Fork for Hibernate 7
Since Spring 7 removed the `org.springframework.orm.hibernate5` package and its `javax.*` support, we have forked the necessary Spring ORM classes into:
`org.grails.orm.hibernate.support.hibernate7`

These classes have been migrated to:
- **Jakarta Namespace**: All `javax.persistence`, `javax.transaction`, and `javax.servlet` imports have been replaced with their `jakarta.*` equivalents.
- **Hibernate 7 API**: Updated to accommodate the removal of legacy APIs (e.g., `Criteria`, `DetachedCriteria`, `Session.load`).
…ar alignment. Implement ChildHibernateDatastore for isolated session routing, resolve bootstrapping circular dependencies, and update

  auto-configuration imports for Boot 4 compatibility. Includes verified unit tests for the new datastore architecture.
…eporting across all 60+ modules, including CodeNarc, PMD, SpotBugs, and Checkstyle.

  Key Changes:
   1. Consolidated XML Reporting: All tools now generate unique XML reports in build/reports/codestyle/ at the root project level.
   2. Aggregate Task: Added a root project task aggregateStyleViolations that parses these XML reports and generates a unified Markdown summary.
   3. Test Filtering:
       * Linting for tests is disabled by default (can be toggled via grails.codestyle.enabled.tests).
@borinquenkid borinquenkid marked this pull request as ready for review March 30, 2026 02:23
Copy link
Copy Markdown
Contributor Author

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not fully reviewed this code, but I saw some changes that I wanted to seek clarification right away. Can you please take a look at the build / license comments?

@jdaugherty jdaugherty changed the base branch from 8.0.x to spring-boot-4 March 31, 2026 21:25
- Revert Liquibase Hibernate 7 versions to 4.27.0 for stability.
- Add no-arg constructor to GormDatabase for Liquibase service discovery.
- Fix JdbcConnection casting in HibernateDatabase.
- Update sequence support detection in MissingSequenceChangeGenerator.
- Replace removed StringUtil.randomIdentifier in UniqueConstraintSnapshotGenerator.
- Update migration specs to support INT and INTEGER type names.
- Fix dependency conflicts and JDK 17 compatibility for Derby.
- Update SBOM license mapping for liquibase-core.
- Rename Liquibase extension classes with 'Hibernate' prefix to avoid shadowing superclass simple names (fixes NM_SAME_SIMPLE_NAME_AS_SUPERCLASS).
- Update service registration files and test sources to reflect class renames.
- Fix NP_NONNULL_RETURN_VIOLATION in HibernateConnection by throwing SQLFeatureNotSupportedException instead of returning null.
- Fix DM_DEFAULT_ENCODING by specifying UTF-8/StandardCharsets.UTF_8 in multiple files.
- Fix potential NP_NULL_ON_SOME_PATH in DatabaseMigrationCommand.groovy with explicit null checks.
@testlens-app

This comment has been minimized.

@testlens-app
Copy link
Copy Markdown

testlens-app bot commented Apr 1, 2026

✅ All tests passed ✅

🏷️ Commit: e8ee4ba
▶️ Tests: 14597 executed
🟡 Checks: 23/27 completed


Learn more about TestLens at testlens.app.

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