Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

EmptyInterceptor is deprecated in Hibernate 6 and gone in Hibernate 7

Your error

EmptyInterceptor in org.hibernate has been deprecated2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The class still extends EmptyInterceptor

Replace extends EmptyInterceptor with implements Interceptor and keep only the methods you need.

Fix
import org.hibernate.Interceptor;

public class AuditInterceptor implements Interceptor {
    // override only the callbacks you use
}

# application.properties
spring.jpa.properties.hibernate.session_factory.interceptor=com.example.AuditInterceptor
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

EmptyInterceptor has been deprecated since Hibernate 6.0 and was removed in 7.0, so on Spring Boot 4 the class no longer compiles. Implement org.hibernate.Interceptor directly, since its methods now have defaults. If the old class overrode onPrepareStatement to change SQL, move that code to a StatementInspector. Applies to Hibernate 6.6 and 7.4.

  • Applies to Hibernate ORM 7.4.15 (Spring Boot 4.2.0), Hibernate ORM 6.6.53 (Spring Boot 3.5.16), JDK 17 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Check which Hibernate ORM version the build resolves, then list the interceptor methods your class overrides. The version tells you whether EmptyInterceptor still exists; the method names tell you which of the causes apply.

Run this first
./mvnw dependency:tree -Dincludes=org.hibernate.orm:hibernate-core
grep -rn "EmptyInterceptor\|onPrepareStatement\|Serializable id" src/main/java

Then find the line you see in this list and open its fix:

  1. 1The class still extends EmptyInterceptorHibernate 6.x compiles with a deprecation warning; Hibernate 7.x fails with cannot find symbol for EmptyInterceptor
  2. 2onPrepareStatement was used to rewrite SQLThe @Override on onPrepareStatement(String sql) fails with does not override or implement a method from a supertype
  3. 3Overridden callbacks still take a Serializable idOn Hibernate 7, methods like onSave or onFlushDirty with a Serializable id parameter no longer compile

What does the error look like?

  • EmptyInterceptor in org.hibernate has been deprecated
  • cannot find symbol symbol: class EmptyInterceptor
  • does not override or implement a method from a supertype

Cause 1 of 3

The class still extends EmptyInterceptor

You seeHibernate 6.x compiles with a deprecation warning; Hibernate 7.x fails with cannot find symbol for EmptyInterceptor

Check

EmptyInterceptor carries @Deprecated(since="6.0") in Hibernate 6, so extending it compiles with a warning. The Hibernate 7.0 migration guide then lists the class as removed, because org.hibernate.Interceptor now gives every method a default body. An upgrade to Spring Boot 4, which brings Hibernate 7, turns the warning into a compile error.

Check
grep -rn "extends EmptyInterceptor" src/main/java

Fix

Replace extends EmptyInterceptor with implements Interceptor and keep only the methods you need. Register it with the hibernate.session_factory.interceptor setting, which Spring Boot passes through from spring.jpa.properties.

Fix
import org.hibernate.Interceptor;

public class AuditInterceptor implements Interceptor {
    // override only the callbacks you use
}

# application.properties
spring.jpa.properties.hibernate.session_factory.interceptor=com.example.AuditInterceptor

Verify

The build compiles with no EmptyInterceptor warning, and the interceptor still runs on a save in a test.

Verify
./mvnw -q compile

Confirmed by docs.jboss.org

Did this fix it?

Cause 2 of 3

onPrepareStatement was used to rewrite SQL

You seeThe @Override on onPrepareStatement(String sql) fails with does not override or implement a method from a supertype

Check

A class that changed SQL in onPrepareStatement breaks after the upgrade because the Interceptor in Hibernate 6.6 and 7.x has no such method any more. Hibernate 5 had already deprecated it with the note to supply a StatementInspector instead. StatementInspector has one method, inspect(String sql), which may return a different SQL string.

Check
grep -rn "onPrepareStatement" src/main/java

Fix

Move the body of onPrepareStatement into a StatementInspector and register it with hibernate.session_factory.statement_inspector. An inspector set this way is shared by all sessions, so keep it thread-safe.

Fix
import org.hibernate.resource.jdbc.spi.StatementInspector;

public class SqlCommentInspector implements StatementInspector {
    @Override
    public String inspect(String sql) {
        return "/* app=shop */ " + sql;
    }
}

# application.properties
spring.jpa.properties.hibernate.session_factory.statement_inspector=com.example.SqlCommentInspector

Verify

With spring.jpa.properties.hibernate.show_sql=true in the test configuration, the logged statements carry your change.

Verify
./mvnw -q test

Confirmed by docs.jboss.org

Did this fix it?

Cause 3 of 3

Overridden callbacks still take a Serializable id

You seeOn Hibernate 7, methods like onSave or onFlushDirty with a Serializable id parameter no longer compile

Check

Hibernate 6.0 changed entity identifiers in Interceptor callbacks from Serializable to Object, and 7.0 removed the old Serializable versions of onLoad, onSave, onFlushDirty, onDelete and the others. In 7.4 onSave itself is deprecated, and the javadoc points to onPersist.

Check
grep -rn "Serializable id" src/main/java

Fix

Change the id parameter to Object and rename onSave to onPersist and onDelete to onRemove. Return true from onPersist or onFlushDirty only when you changed the state array.

Fix
@Override
public boolean onPersist(Object entity, Object id, Object[] state,
                         String[] propertyNames, Type[] types) {
    // set created-at or similar fields in state[]
    return true;
}

Verify

The class compiles without override errors and the callback fires when a test persists an entity.

Verify
./mvnw -q test

Confirmed by docs.jboss.org

Did this fix it?

How do I stop it coming back?

  • Compile with -Xlint:deprecation in CI so Hibernate deprecations show up a major version before the removal.
  • Read the Hibernate migration guide for each major version before bumping Spring Boot, since Boot 4 moves Hibernate from 6.6 to 7.x.
  • Keep SQL rewriting in a StatementInspector and entity callbacks in an Interceptor, so each piece follows one stable API.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.