You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/03/01 19:34:46 UTC

(grails-core) branch 8.0.x-hibernate7 updated (31123d8c7d -> de8c2610c8)

This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a change to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git


    from 31123d8c7d refactor strategy Mapping
     new 20a717512e fix: restore 4-space indentation in hibernate7 grails-plugin support classes
     new de8c2610c8 chore: replace Checkstyle with Spotless and add PMD globally

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../config/pmd/pmd.xml                             |  15 +-
 gradle.properties                                  |   2 +-
 gradle/code-style-config.gradle                    |  49 ++-
 grails-data-hibernate7/core/build.gradle           |  32 +-
 ...urceAggregatePersistenceContextInterceptor.java | 137 ++++---
 .../AggregatePersistenceContextInterceptor.java    |  31 +-
 .../GrailsOpenSessionInViewInterceptor.java        |  83 ++---
 .../HibernatePersistenceContextInterceptor.java    | 395 +++++++++++----------
 ...nFactoryAwarePersistenceContextInterceptor.java |  11 +-
 9 files changed, 380 insertions(+), 375 deletions(-)
 copy build-logic/plugins/src/main/resources/META-INF/org.apache.grails.buildsrc.codestyle/checkstyle/checkstyle-suppressions.xml => etc/config/pmd/pmd.xml (63%)


(grails-core) 02/02: chore: replace Checkstyle with Spotless and add PMD globally

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit de8c2610c801633ec5565c34d683b5be8d4c3278
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sun Mar 1 13:25:36 2026 -0600

    chore: replace Checkstyle with Spotless and add PMD globally
    
    - 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 <22...@users.noreply.github.com>
---
 etc/config/pmd/pmd.xml                   | 31 ++++++++++++++++++++
 gradle.properties                        |  2 +-
 gradle/code-style-config.gradle          | 49 +++++++++++++++++++++++++-------
 grails-data-hibernate7/core/build.gradle | 32 ++-------------------
 4 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/etc/config/pmd/pmd.xml b/etc/config/pmd/pmd.xml
new file mode 100644
index 0000000000..cf494a7125
--- /dev/null
+++ b/etc/config/pmd/pmd.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<ruleset name="Grails PMD Rules"
+        xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
+
+    <description>PMD ruleset for the Grails codebase</description>
+
+    <rule ref="category/java/bestpractices.xml"/>
+    <rule ref="category/java/errorprone.xml"/>
+    <rule ref="category/java/security.xml"/>
+
+</ruleset>
diff --git a/gradle.properties b/gradle.properties
index e87a20b74e..1c4cb7424d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -68,7 +68,7 @@ micronautHttpClientVersion=4.9.9
 micronautSerdeJacksonVersion=2.11.0
 
 # build dependencies for code quality checks
-checkstyleVersion=11.0.0
+pmdVersion=6.55.0
 codenarcVersion=3.6.0-groovy-4.0
 
 # This prevents the Grails Gradle Plugin from unnecessarily excluding slf4j-simple in the generated POMs
diff --git a/gradle/code-style-config.gradle b/gradle/code-style-config.gradle
index 9c3ad1f3c1..d7a74d652d 100644
--- a/gradle/code-style-config.gradle
+++ b/gradle/code-style-config.gradle
@@ -17,26 +17,46 @@
  *  under the License.
  */
 
-apply plugin: 'checkstyle'
+apply plugin: 'pmd'
 apply plugin: 'codenarc'
+apply plugin: 'com.diffplug.spotless'
 
-extensions.configure(CheckstyleExtension) {
-    // Explicit `it` is required in extension configuration
-    it.configDirectory = rootProject.layout.projectDirectory.dir('etc/config/checkstyle').asFile
-    it.maxWarnings = 0
-    it.showViolations = true
+// PMD — static analysis for Java sources
+extensions.configure(PmdExtension) {
+    it.ruleSetFiles = rootProject.files('etc/config/pmd/pmd.xml')
+    it.ruleSets = [] // clear defaults so only pmd.xml is used
     it.ignoreFailures = false
-    it.toolVersion = checkstyleVersion
+    it.consoleOutput = true
+    it.toolVersion = pmdVersion
 }
 
+// CodeNarc — static analysis for Groovy sources (unchanged)
 extensions.configure(CodeNarcExtension) {
     // Explicit `it` is required in extension configuration
     it.configFile = rootProject.layout.projectDirectory.file('etc/config/codenarc/codenarc.groovy').asFile
     it.toolVersion = codenarcVersion
 }
 
+// Spotless — formatting for Java sources, enforcing the same rules previously checked by Checkstyle:
+//   - 4-space indentation (palantirJavaFormat)
+//   - custom import ordering matching the former Checkstyle ImportOrderCheck groups
+//     (java|javax → groovy → jakarta → other → spring → grails → static last)
+//   - no unused imports, no trailing whitespace, newline at end of file
+spotless {
+    java {
+        palantirJavaFormat()
+        importOrder('java|javax', 'groovy|org.apache.groovy|org.codehaus.groovy', 'jakarta', '', 'io.spring|org.springframework', 'grails|org.apache.grails|org.grails', '\\#')
+        removeUnusedImports()
+        trimTrailingWhitespace()
+        endWithNewline()
+        target fileTree(project.projectDir) {
+            include 'src/main/**/*.java'
+        }
+    }
+}
+
 // Do not run Code Style checks if the property 'skipCodeStyle' is defined
-tasks.withType(Checkstyle).configureEach {
+tasks.withType(Pmd).configureEach {
     group = 'verification'
     onlyIf { !project.hasProperty('skipCodeStyle') }
 }
@@ -44,15 +64,19 @@ tasks.withType(CodeNarc).configureEach {
     group = 'verification'
     onlyIf { !project.hasProperty('skipCodeStyle') }
 }
+tasks.matching { it.name.startsWith('spotless') }.configureEach {
+    onlyIf { !project.hasProperty('skipCodeStyle') }
+}
 
 tasks.register('codeStyle') {
     group = 'verification'
     description = 'Runs code style checks'
-    dependsOn(tasks.withType(Checkstyle))
+    dependsOn(tasks.withType(Pmd))
     dependsOn(tasks.withType(CodeNarc))
+    dependsOn('spotlessCheck')
 }
 
-tasks.named('checkstyleTest') {
+tasks.named('pmdTest') {
     enabled = false // Do not check test sources at this time
 }
 
@@ -66,4 +90,9 @@ gradle.taskGraph.whenReady {
             enabled = false // Do not check test sources at this time
         }
     }
+    if (tasks.findByName('pmdIntegrationTest')) {
+        tasks.named('pmdIntegrationTest') {
+            enabled = false // Do not check test sources at this time
+        }
+    }
 }
diff --git a/grails-data-hibernate7/core/build.gradle b/grails-data-hibernate7/core/build.gradle
index 8b43bbe4af..c7c3d230c1 100644
--- a/grails-data-hibernate7/core/build.gradle
+++ b/grails-data-hibernate7/core/build.gradle
@@ -25,8 +25,6 @@ plugins {
     id 'java-library'
     id 'jacoco'
     id 'com.github.spotbugs'
-    id 'pmd'
-    id 'com.diffplug.spotless'
     id 'org.apache.grails.buildsrc.properties'
 }
 
@@ -138,6 +136,7 @@ dependencies {
 
 apply {
     from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
+    from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
     from rootProject.layout.projectDirectory.file('gradle/hibernate7-test-config.gradle')
     from rootProject.layout.projectDirectory.file('gradle/grails-data-tck-config.gradle')
     from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
@@ -168,33 +167,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
     }
 }
 
-pmd {
-    consoleOutput = true
-    ignoreFailures = true
-//    ruleSets = ['category/java/bestpractices.xml', 'category/java/errorprone.xml', 'category/java/security.xml']
-    // toolVersion = '7.0.0'   // optional: override default PMD version if needed
-}
-
 tasks.named('check') {
-    dependsOn 'spotbugsMain', 'pmdMain'
-}
-
-// 2. Configure Spotless
-spotless {
-    java {
-        // Use rootProject.projectDir to ensure the path is absolute from the root
-        def licenseFile = new File(rootProject.projectDir, 'grails-forge/config/spotless.license.java')
-        if (licenseFile.exists()) {
-            licenseHeaderFile licenseFile
-        }
-
-        googleJavaFormat()
-
-        // This targets the specific file in your Checkstyle report
-        target 'src/main/java/**/*.java', 'src/main/groovy/**/*.java'
-
-        removeUnusedImports()
-        trimTrailingWhitespace()
-        endWithNewline()
-    }
+    dependsOn 'spotbugsMain'
 }


(grails-core) 01/02: fix: restore 4-space indentation in hibernate7 grails-plugin support classes

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 20a717512ecabbc6aab6fc01b486ff194291aa37
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sun Mar 1 12:35:19 2026 -0600

    fix: restore 4-space indentation in hibernate7 grails-plugin support 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 <22...@users.noreply.github.com>
---
 ...urceAggregatePersistenceContextInterceptor.java | 137 ++++---
 .../AggregatePersistenceContextInterceptor.java    |  31 +-
 .../GrailsOpenSessionInViewInterceptor.java        |  83 ++---
 .../HibernatePersistenceContextInterceptor.java    | 395 +++++++++++----------
 ...nFactoryAwarePersistenceContextInterceptor.java |  11 +-
 5 files changed, 326 insertions(+), 331 deletions(-)

diff --git a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AbstractMultipleDataSourceAggregatePersistenceContextInterceptor.java b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AbstractMultipleDataSourceAggregatePersistenceContextInterceptor.java
index 6aa3f446b7..8fda4e23b4 100644
--- a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AbstractMultipleDataSourceAggregatePersistenceContextInterceptor.java
+++ b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AbstractMultipleDataSourceAggregatePersistenceContextInterceptor.java
@@ -18,107 +18,102 @@
  */
 package org.grails.plugin.hibernate.support;
 
-import grails.persistence.support.PersistenceContextInterceptor;
 import java.util.ArrayList;
 import java.util.List;
+
+import org.hibernate.SessionFactory;
+
+import grails.persistence.support.PersistenceContextInterceptor;
 import org.grails.datastore.mapping.core.connections.ConnectionSource;
 import org.grails.datastore.mapping.core.connections.ConnectionSources;
 import org.grails.orm.hibernate.AbstractHibernateDatastore;
 import org.grails.orm.hibernate.connections.HibernateConnectionSourceSettings;
-import org.hibernate.SessionFactory;
 
 /**
- * Abstract implementation of the {@link grails.persistence.support.PersistenceContextInterceptor}
- * interface that supports multiple data sources
+ * Abstract implementation of the {@link grails.persistence.support.PersistenceContextInterceptor} interface that supports multiple data sources
  *
  * @author Graeme Rocher
  * @since 2.0.7
  */
-public abstract class AbstractMultipleDataSourceAggregatePersistenceContextInterceptor
-    implements PersistenceContextInterceptor {
-
-  protected final List<PersistenceContextInterceptor> interceptors = new ArrayList<>();
-  protected final AbstractHibernateDatastore hibernateDatastore;
-
-  public AbstractMultipleDataSourceAggregatePersistenceContextInterceptor(
-      AbstractHibernateDatastore hibernateDatastore) {
-    this.hibernateDatastore = hibernateDatastore;
-    ConnectionSources<SessionFactory, HibernateConnectionSourceSettings> connectionSources =
-        hibernateDatastore.getConnectionSources();
-    Iterable<ConnectionSource<SessionFactory, HibernateConnectionSourceSettings>>
-        allConnectionSources = connectionSources.getAllConnectionSources();
-    for (ConnectionSource<SessionFactory, HibernateConnectionSourceSettings> connectionSource :
-        allConnectionSources) {
-      SessionFactoryAwarePersistenceContextInterceptor interceptor =
-          createPersistenceContextInterceptor(connectionSource.getName());
-      this.interceptors.add(interceptor);
+public abstract class AbstractMultipleDataSourceAggregatePersistenceContextInterceptor implements PersistenceContextInterceptor {
+
+    protected final List<PersistenceContextInterceptor> interceptors = new ArrayList<>();
+    protected final AbstractHibernateDatastore hibernateDatastore;
+
+    public AbstractMultipleDataSourceAggregatePersistenceContextInterceptor(AbstractHibernateDatastore hibernateDatastore) {
+        this.hibernateDatastore = hibernateDatastore;
+        ConnectionSources<SessionFactory, HibernateConnectionSourceSettings> connectionSources = hibernateDatastore.getConnectionSources();
+        Iterable<ConnectionSource<SessionFactory, HibernateConnectionSourceSettings>> allConnectionSources = connectionSources.getAllConnectionSources();
+        for (ConnectionSource<SessionFactory, HibernateConnectionSourceSettings> connectionSource : allConnectionSources) {
+            SessionFactoryAwarePersistenceContextInterceptor interceptor = createPersistenceContextInterceptor(connectionSource.getName());
+            this.interceptors.add(interceptor);
+        }
     }
-  }
-
-  public boolean isOpen() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      if (interceptor.isOpen()) {
-        // true at least one is true
-        return true;
-      }
+
+    public boolean isOpen() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            if (interceptor.isOpen()) {
+                // true at least one is true
+                return true;
+            }
+        }
+        return false;
     }
-    return false;
-  }
 
-  public void reconnect() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.reconnect();
+    public void reconnect() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.reconnect();
+        }
     }
-  }
 
-  public void destroy() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      try {
-        if (interceptor.isOpen()) {
-          interceptor.destroy();
+    public void destroy() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            try {
+                if (interceptor.isOpen()) {
+                    interceptor.destroy();
+                }
+            } catch (Exception e) {
+                // ignore exception
+            }
         }
-      } catch (Exception e) {
-        // ignore exception
-      }
     }
-  }
 
-  public void clear() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.clear();
+    public void clear() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.clear();
+        }
     }
-  }
 
-  public void disconnect() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.disconnect();
+    public void disconnect() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.disconnect();
+        }
     }
-  }
 
-  public void flush() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.flush();
+    public void flush() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.flush();
+        }
     }
-  }
 
-  public void init() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.init();
+    public void init() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.init();
+        }
     }
-  }
 
-  public void setReadOnly() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.setReadOnly();
+    public void setReadOnly() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.setReadOnly();
+        }
     }
-  }
 
-  public void setReadWrite() {
-    for (PersistenceContextInterceptor interceptor : interceptors) {
-      interceptor.setReadWrite();
+    public void setReadWrite() {
+        for (PersistenceContextInterceptor interceptor : interceptors) {
+            interceptor.setReadWrite();
+        }
     }
-  }
 
-  protected abstract SessionFactoryAwarePersistenceContextInterceptor
-      createPersistenceContextInterceptor(String dataSourceName);
+    protected abstract SessionFactoryAwarePersistenceContextInterceptor createPersistenceContextInterceptor(String dataSourceName);
+
 }
diff --git a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AggregatePersistenceContextInterceptor.java b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AggregatePersistenceContextInterceptor.java
index 49a336dbcc..060681f57d 100644
--- a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AggregatePersistenceContextInterceptor.java
+++ b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/AggregatePersistenceContextInterceptor.java
@@ -16,32 +16,29 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
+
 package org.grails.plugin.hibernate.support;
 
 import org.grails.orm.hibernate.AbstractHibernateDatastore;
 
 /**
- * Concrete implementation of the {@link
- * AbstractMultipleDataSourceAggregatePersistenceContextInterceptor} class for Hibernate 4
+ * Concrete implementation of the {@link AbstractMultipleDataSourceAggregatePersistenceContextInterceptor} class for Hibernate 4
  *
  * @author Graeme Rocher
  * @author Burt Beckwith
  */
-public class AggregatePersistenceContextInterceptor
-    extends AbstractMultipleDataSourceAggregatePersistenceContextInterceptor {
+public class AggregatePersistenceContextInterceptor extends AbstractMultipleDataSourceAggregatePersistenceContextInterceptor {
+
+    public AggregatePersistenceContextInterceptor(AbstractHibernateDatastore hibernateDatastore) {
+        super(hibernateDatastore);
+    }
 
-  public AggregatePersistenceContextInterceptor(AbstractHibernateDatastore hibernateDatastore) {
-    super(hibernateDatastore);
-  }
+    @Override
+    protected SessionFactoryAwarePersistenceContextInterceptor createPersistenceContextInterceptor(String dataSourceName) {
+        HibernatePersistenceContextInterceptor interceptor = new HibernatePersistenceContextInterceptor(dataSourceName);
+        AbstractHibernateDatastore datastoreForConnection = hibernateDatastore.getDatastoreForConnection(dataSourceName);
+        interceptor.setHibernateDatastore(datastoreForConnection);
+        return interceptor;
+    }
 
-  @Override
-  protected SessionFactoryAwarePersistenceContextInterceptor createPersistenceContextInterceptor(
-      String dataSourceName) {
-    HibernatePersistenceContextInterceptor interceptor =
-        new HibernatePersistenceContextInterceptor(dataSourceName);
-    AbstractHibernateDatastore datastoreForConnection =
-        hibernateDatastore.getDatastoreForConnection(dataSourceName);
-    interceptor.setHibernateDatastore(datastoreForConnection);
-    return interceptor;
-  }
 }
diff --git a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/GrailsOpenSessionInViewInterceptor.java b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/GrailsOpenSessionInViewInterceptor.java
index 46502d0671..62bc0fdf0d 100644
--- a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/GrailsOpenSessionInViewInterceptor.java
+++ b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/GrailsOpenSessionInViewInterceptor.java
@@ -18,9 +18,9 @@
  */
 package org.grails.plugin.hibernate.support;
 
-import org.grails.orm.hibernate.AbstractHibernateDatastore;
 import org.hibernate.FlushMode;
 import org.hibernate.Session;
+
 import org.springframework.dao.DataAccessException;
 import org.springframework.dao.DataAccessResourceFailureException;
 import org.springframework.orm.hibernate5.SessionHolder;
@@ -29,57 +29,60 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
 import org.springframework.ui.ModelMap;
 import org.springframework.web.context.request.WebRequest;
 
+import org.grails.orm.hibernate.AbstractHibernateDatastore;
+
 /**
- * Extends the default spring OSIV and doesn't flush the session if it has been set to MANUAL on the
- * session itself.
+ * Extends the default spring OSIV and doesn't flush the session if it has been set
+ * to MANUAL on the session itself.
  *
  * @author Graeme Rocher
  * @since 0.5
  */
 public class GrailsOpenSessionInViewInterceptor extends OpenSessionInViewInterceptor {
 
-  protected FlushMode hibernateFlushMode = FlushMode.MANUAL;
+    protected FlushMode hibernateFlushMode = FlushMode.MANUAL;
 
-  @Override
-  protected Session openSession() throws DataAccessResourceFailureException {
-    Session session = super.openSession();
-    applyFlushMode(session);
-    return session;
-  }
+    @Override
+    protected Session openSession() throws DataAccessResourceFailureException {
+        Session session = super.openSession();
+        applyFlushMode(session);
+        return session;
+    }
 
-  protected void applyFlushMode(Session session) {
-    session.setHibernateFlushMode(hibernateFlushMode);
-  }
+    protected void applyFlushMode(Session session) {
+        session.setHibernateFlushMode(hibernateFlushMode);
+    }
 
-  @Override
-  public void postHandle(WebRequest request, ModelMap model) throws DataAccessException {
-    SessionHolder sessionHolder =
-        (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
-    Session session = sessionHolder != null ? sessionHolder.getSession() : null;
-    try {
-      super.postHandle(request, model);
-      FlushMode flushMode = session != null ? session.getHibernateFlushMode() : null;
-      boolean isNotManual = flushMode != FlushMode.MANUAL && flushMode != FlushMode.COMMIT;
-      if (session != null && isNotManual) {
-        if (logger.isDebugEnabled()) {
-          logger.debug("Eagerly flushing Hibernate session");
+    @Override
+    public void postHandle(WebRequest request, ModelMap model) throws DataAccessException {
+        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
+        Session session = sessionHolder != null ? sessionHolder.getSession() : null;
+        try {
+            super.postHandle(request, model);
+            FlushMode flushMode = session != null ? session.getHibernateFlushMode() : null;
+            boolean isNotManual = flushMode != FlushMode.MANUAL && flushMode != FlushMode.COMMIT;
+            if (session != null && isNotManual) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Eagerly flushing Hibernate session");
+                }
+                session.flush();
+            }
+        }
+        finally {
+            if (session != null) {
+                session.setHibernateFlushMode(FlushMode.MANUAL);
+            }
         }
-        session.flush();
-      }
-    } finally {
-      if (session != null) {
-        session.setHibernateFlushMode(FlushMode.MANUAL);
-      }
     }
-  }
 
-  public void setHibernateDatastore(AbstractHibernateDatastore hibernateDatastore) {
-    String defaultFlushModeName = hibernateDatastore.getDefaultFlushModeName();
-    if (hibernateDatastore.isOsivReadOnly()) {
-      this.hibernateFlushMode = FlushMode.MANUAL;
-    } else {
-      this.hibernateFlushMode = FlushMode.valueOf(defaultFlushModeName);
+    public void setHibernateDatastore(AbstractHibernateDatastore hibernateDatastore) {
+        String defaultFlushModeName = hibernateDatastore.getDefaultFlushModeName();
+        if (hibernateDatastore.isOsivReadOnly()) {
+            this.hibernateFlushMode = FlushMode.MANUAL;
+        }
+        else {
+            this.hibernateFlushMode = FlushMode.valueOf(defaultFlushModeName);
+        }
+        setSessionFactory(hibernateDatastore.getSessionFactory());
     }
-    setSessionFactory(hibernateDatastore.getSessionFactory());
-  }
 }
diff --git a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/HibernatePersistenceContextInterceptor.java b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/HibernatePersistenceContextInterceptor.java
index d822c404be..bd8b2f41e5 100644
--- a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/HibernatePersistenceContextInterceptor.java
+++ b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/HibernatePersistenceContextInterceptor.java
@@ -16,227 +16,228 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
+
 package org.grails.plugin.hibernate.support;
 
-import grails.persistence.support.PersistenceContextInterceptor;
-import grails.validation.DeferredBindingActions;
 import java.sql.Connection;
 import java.util.Deque;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentLinkedDeque;
-import org.grails.core.lifecycle.ShutdownOperations;
-import org.grails.datastore.mapping.core.connections.ConnectionSource;
-import org.grails.orm.hibernate.AbstractHibernateDatastore;
-import org.grails.orm.hibernate.support.HibernateRuntimeUtils;
+
 import org.hibernate.FlushMode;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import org.springframework.orm.hibernate5.SessionFactoryUtils;
 import org.springframework.orm.hibernate5.SessionHolder;
 import org.springframework.transaction.support.TransactionSynchronizationManager;
 
+import grails.persistence.support.PersistenceContextInterceptor;
+import grails.validation.DeferredBindingActions;
+import org.grails.core.lifecycle.ShutdownOperations;
+import org.grails.datastore.mapping.core.connections.ConnectionSource;
+import org.grails.orm.hibernate.AbstractHibernateDatastore;
+import org.grails.orm.hibernate.support.HibernateRuntimeUtils;
+
 /**
  * @author Graeme Rocher
  * @since 0.4
  */
-public class HibernatePersistenceContextInterceptor
-    implements PersistenceContextInterceptor, SessionFactoryAwarePersistenceContextInterceptor {
+public class HibernatePersistenceContextInterceptor implements PersistenceContextInterceptor, SessionFactoryAwarePersistenceContextInterceptor {
 
-  private static final Logger LOG =
-      LoggerFactory.getLogger(HibernatePersistenceContextInterceptor.class);
-  private AbstractHibernateDatastore hibernateDatastore;
+    private static final Logger LOG = LoggerFactory.getLogger(HibernatePersistenceContextInterceptor.class);
+    private AbstractHibernateDatastore hibernateDatastore;
 
-  private static ThreadLocal<Map<String, Boolean>> participate =
-      ThreadLocal.withInitial(HashMap::new);
+    private static ThreadLocal<Map<String, Boolean>> participate = ThreadLocal.withInitial(HashMap::new);
 
-  private static ThreadLocal<Map<String, Integer>> nestingCount =
-      ThreadLocal.withInitial(HashMap::new);
+    private static ThreadLocal<Map<String, Integer>> nestingCount = ThreadLocal.withInitial(HashMap::new);
 
-  private String dataSourceName;
+    private String dataSourceName;
 
-  static {
-    ShutdownOperations.addOperation(
-        () -> {
-          participate.remove();
-          nestingCount.remove();
+    static {
+        ShutdownOperations.addOperation(() -> {
+            participate.remove();
+            nestingCount.remove();
         });
-  }
-
-  private Deque<Connection> disconnected = new ConcurrentLinkedDeque<>();
-  private final boolean transactionRequired;
-
-  public HibernatePersistenceContextInterceptor() {
-    this(ConnectionSource.DEFAULT);
-  }
-
-  /**
-   * @param dataSourceName a name of dataSource
-   */
-  public HibernatePersistenceContextInterceptor(String dataSourceName) {
-    this.dataSourceName = dataSourceName;
-    this.transactionRequired = true;
-  }
-
-  /* (non-Javadoc)
-   * @see org.apache.groovy.grails.support.PersistenceContextInterceptor#destroy()
-   */
-  public void destroy() {
-    DeferredBindingActions.clear();
-    if (!disconnected.isEmpty()) {
-      disconnected.pop();
-    }
-    if (getSessionFactory() == null || decNestingCount() > 0 || getParticipate()) {
-      return;
-    }
-
-    // single session mode
-    SessionHolder holder =
-        (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
-    LOG.debug("Closing single Hibernate session in GrailsDispatcherServlet");
-    try {
-      disconnected.clear();
-      SessionFactoryUtils.closeSession(holder.getSession());
-    } catch (RuntimeException ex) {
-      LOG.error("Unexpected exception on closing Hibernate Session", ex);
-    }
-  }
-
-  public void disconnect() {
-    throw new UnsupportedOperationException("disconnect is not supported by Hibernate 6");
-  }
-
-  public void reconnect() {
-    throw new UnsupportedOperationException("reconnect is not supported by Hibernate 6");
-  }
-
-  public void flush() {
-    if (getSessionFactory() == null) return;
-    if (!getParticipate()) {
-      if (!transactionRequired) {
-        getSession().flush();
-      } else if (TransactionSynchronizationManager.isSynchronizationActive()) {
-        getSession().flush();
-      }
-    }
-  }
-
-  public void clear() {
-    if (getSessionFactory() == null) return;
-    getSession().clear();
-  }
-
-  public void setReadOnly() {
-    if (getSessionFactory() == null) return;
-    getSession().setHibernateFlushMode(FlushMode.MANUAL);
-  }
-
-  public void setReadWrite() {
-    if (getSessionFactory() == null) return;
-    getSession().setHibernateFlushMode(FlushMode.AUTO);
-  }
-
-  public boolean isOpen() {
-    if (getSessionFactory() == null) return false;
-    try {
-      return getSession(false).isOpen();
-    } catch (Exception e) {
-      return false;
-    }
-  }
-
-  /* (non-Javadoc)
-   * @see org.apache.groovy.grails.support.PersistenceContextInterceptor#init()
-   */
-  public void init() {
-    if (incNestingCount() > 1) {
-      return;
-    }
-    SessionFactory sf = getSessionFactory();
-    if (sf == null) {
-      return;
-    }
-    if (TransactionSynchronizationManager.hasResource(sf)) {
-      // Do not modify the Session: just set the participate flag.
-      setParticipate(true);
-    } else {
-      setParticipate(false);
-      LOG.debug("Opening single Hibernate session in HibernatePersistenceContextInterceptor");
-      Session session = getSession();
-      HibernateRuntimeUtils.enableDynamicFilterEnablerIfPresent(sf, session);
-      TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
-    }
-  }
-
-  private Session getSession() {
-    return getSession(true);
-  }
-
-  private Session getSession(boolean allowCreate) {
-
-    Object value = TransactionSynchronizationManager.getResource(getSessionFactory());
-    if (value instanceof Session) {
-      return (Session) value;
-    }
-
-    if (value instanceof SessionHolder) {
-      SessionHolder sessionHolder = (SessionHolder) value;
-      return sessionHolder.getSession();
-    }
-
-    if (allowCreate && hibernateDatastore != null) {
-      return hibernateDatastore.openSession();
-    }
-
-    throw new IllegalStateException(
-        "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here");
-  }
-
-  /**
-   * @return the sessionFactory
-   */
-  public SessionFactory getSessionFactory() {
-    return hibernateDatastore.getSessionFactory();
-  }
-
-  public void setHibernateDatastore(AbstractHibernateDatastore hibernateDatastore) {
-    this.hibernateDatastore = hibernateDatastore;
-  }
-
-  @Override
-  public void setSessionFactory(SessionFactory sessionFactory) {
-    // ignore
-  }
-
-  private int incNestingCount() {
-    Map<String, Integer> map = nestingCount.get();
-    Integer current = map.get(dataSourceName);
-    int value = (current != null) ? current + 1 : 1;
-    map.put(dataSourceName, value);
-    return value;
-  }
-
-  private int decNestingCount() {
-    Map<String, Integer> map = nestingCount.get();
-    Integer current = map.get(dataSourceName);
-    int value = (current != null) ? current - 1 : 0;
-    if (value < 0) {
-      value = 0;
-    }
-    map.put(dataSourceName, value);
-    return value;
-  }
-
-  private void setParticipate(boolean flag) {
-    Map<String, Boolean> map = participate.get();
-    map.put(dataSourceName, flag);
-  }
-
-  private boolean getParticipate() {
-    Map<String, Boolean> map = participate.get();
-    Boolean ret = map.get(dataSourceName);
-    return (ret != null) ? ret : false;
-  }
+    }
+
+    private Deque<Connection> disconnected = new ConcurrentLinkedDeque<>();
+    private final boolean transactionRequired;
+
+    public HibernatePersistenceContextInterceptor() {
+        this(ConnectionSource.DEFAULT);
+    }
+
+    /**
+     * @param dataSourceName a name of dataSource
+     */
+    public HibernatePersistenceContextInterceptor(String dataSourceName) {
+        this.dataSourceName = dataSourceName;
+        this.transactionRequired = true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.groovy.grails.support.PersistenceContextInterceptor#destroy()
+     */
+    public void destroy() {
+        DeferredBindingActions.clear();
+        if (!disconnected.isEmpty()) {
+            disconnected.pop();
+        }
+        if (getSessionFactory() == null || decNestingCount() > 0 || getParticipate()) {
+            return;
+        }
+
+        // single session mode
+        SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
+        LOG.debug("Closing single Hibernate session in GrailsDispatcherServlet");
+        try {
+            disconnected.clear();
+            SessionFactoryUtils.closeSession(holder.getSession());
+        }
+        catch (RuntimeException ex) {
+            LOG.error("Unexpected exception on closing Hibernate Session", ex);
+        }
+    }
+
+    public void disconnect() {
+        throw new UnsupportedOperationException("disconnect is not supported by Hibernate 6");
+    }
+
+    public void reconnect() {
+        throw new UnsupportedOperationException("reconnect is not supported by Hibernate 6");
+    }
+
+    public void flush() {
+        if (getSessionFactory() == null) return;
+        if (!getParticipate()) {
+            if (!transactionRequired) {
+                getSession().flush();
+            }
+            else if (TransactionSynchronizationManager.isSynchronizationActive()) {
+                getSession().flush();
+            }
+        }
+    }
+
+    public void clear() {
+        if (getSessionFactory() == null) return;
+        getSession().clear();
+    }
+
+    public void setReadOnly() {
+        if (getSessionFactory() == null) return;
+        getSession().setHibernateFlushMode(FlushMode.MANUAL);
+    }
+
+    public void setReadWrite() {
+        if (getSessionFactory() == null) return;
+        getSession().setHibernateFlushMode(FlushMode.AUTO);
+    }
+
+    public boolean isOpen() {
+        if (getSessionFactory() == null) return false;
+        try {
+            return getSession(false).isOpen();
+        }
+        catch (Exception e) {
+            return false;
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.groovy.grails.support.PersistenceContextInterceptor#init()
+     */
+    public void init() {
+        if (incNestingCount() > 1) {
+            return;
+        }
+        SessionFactory sf = getSessionFactory();
+        if (sf == null) {
+            return;
+        }
+        if (TransactionSynchronizationManager.hasResource(sf)) {
+            // Do not modify the Session: just set the participate flag.
+            setParticipate(true);
+        }
+        else {
+            setParticipate(false);
+            LOG.debug("Opening single Hibernate session in HibernatePersistenceContextInterceptor");
+            Session session = getSession();
+            HibernateRuntimeUtils.enableDynamicFilterEnablerIfPresent(sf, session);
+            TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
+        }
+    }
+
+    private Session getSession() {
+        return getSession(true);
+    }
+
+    private Session getSession(boolean allowCreate) {
+
+        Object value = TransactionSynchronizationManager.getResource(getSessionFactory());
+        if (value instanceof Session) {
+            return (Session) value;
+        }
+
+        if (value instanceof SessionHolder) {
+            SessionHolder sessionHolder = (SessionHolder) value;
+            return sessionHolder.getSession();
+        }
+
+        if (allowCreate && hibernateDatastore != null) {
+            return hibernateDatastore.openSession();
+        }
+
+        throw new IllegalStateException("No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here");
+    }
+
+    /**
+     * @return the sessionFactory
+     */
+    public SessionFactory getSessionFactory() {
+        return hibernateDatastore.getSessionFactory();
+    }
+
+    public void setHibernateDatastore(AbstractHibernateDatastore hibernateDatastore) {
+        this.hibernateDatastore = hibernateDatastore;
+    }
+
+    @Override
+    public void setSessionFactory(SessionFactory sessionFactory) {
+        // ignore
+    }
+
+    private int incNestingCount() {
+        Map<String, Integer> map = nestingCount.get();
+        Integer current = map.get(dataSourceName);
+        int value = (current != null) ? current + 1 : 1;
+        map.put(dataSourceName, value);
+        return value;
+    }
+
+    private int decNestingCount() {
+        Map<String, Integer> map = nestingCount.get();
+        Integer current = map.get(dataSourceName);
+        int value = (current != null) ? current - 1 : 0;
+        if (value < 0) {
+            value = 0;
+        }
+        map.put(dataSourceName, value);
+        return value;
+    }
+
+    private void setParticipate(boolean flag) {
+        Map<String, Boolean> map = participate.get();
+        map.put(dataSourceName, flag);
+    }
+
+    private boolean getParticipate() {
+        Map<String, Boolean> map = participate.get();
+        Boolean ret = map.get(dataSourceName);
+        return (ret != null) ? ret : false;
+    }
 }
diff --git a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/SessionFactoryAwarePersistenceContextInterceptor.java b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/SessionFactoryAwarePersistenceContextInterceptor.java
index 762d70c095..41ec12ebf9 100644
--- a/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/SessionFactoryAwarePersistenceContextInterceptor.java
+++ b/grails-data-hibernate7/grails-plugin/src/main/groovy/org/grails/plugin/hibernate/support/SessionFactoryAwarePersistenceContextInterceptor.java
@@ -18,18 +18,17 @@
  */
 package org.grails.plugin.hibernate.support;
 
-import grails.persistence.support.PersistenceContextInterceptor;
 import org.hibernate.SessionFactory;
 
+import grails.persistence.support.PersistenceContextInterceptor;
+
 /**
- * Interface for {@link grails.persistence.support.PersistenceContextInterceptor} instances that are
- * aware of the {@link org.hibernate.SessionFactory}
+ * Interface for {@link grails.persistence.support.PersistenceContextInterceptor} instances that are aware of the {@link org.hibernate.SessionFactory}
  *
  * @author Graeme Rocher
  * @since 2.0.7
  */
-public interface SessionFactoryAwarePersistenceContextInterceptor
-    extends PersistenceContextInterceptor {
+public interface SessionFactoryAwarePersistenceContextInterceptor extends PersistenceContextInterceptor {
 
-  void setSessionFactory(SessionFactory sessionFactory);
+    void setSessionFactory(SessionFactory sessionFactory);
 }