Custom SqlStatementLogger setup

I am trying to setup my own SqlStatementLogger, and it looks like that would require overriding JdbcServices service, but I am not finding a way to do that.

How can i configure my own JdbcServices service override?

Am I missing other (hopefully easier) way to replace SqlStatementLogger class?

Thanks

You need a custom SqlStatementLoggerInitiator. See hibernate-orm/SqlStatementLoggerInitiator.java at e5f08de40e957e933511ad1c2d12c06897c08978 · hibernate/hibernate-orm · GitHub

Thank you for your replay @beikov

I can’t see how registering my logger as a service could help, because JdbsServices class instantiates a new SqlStatementLogger without checking services, so logging classes which get the logger from the JdbcService will never get mine.

Might be that we didn’t backport this from the main branch to the 6.2 branch. Wdyt @Sanne, should we backport [HHH-16443] - Hibernate JIRA to 6.2?

Looks like we already backported that. I’ll update the JIRA to reflect this.

Look like this is still the issue in 6.2.11:

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlStatementLogger.isFormat()" because "this.sqlStatementLogger" is null
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:277)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:239)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:216)
...
Caused by: java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlStatementLogger.isFormat()" because "this.sqlStatementLogger" is null
        at org.hibernate.reactive.pool.impl.SqlClientConnection.feedback(SqlClientConnection.java:270)
        at org.hibernate.reactive.pool.impl.SqlClientConnection.preparedQuery(SqlClientConnection.java:250)
        at org.hibernate.reactive.pool.impl.SqlClientConnection.select(SqlClientConnection.java:113)
        at org.hibernate.reactive.provider.service.NoJdbcEnvironmentInitiator$DialectBuilder.resolutionInfoStage(NoJdbcEnvironmentInitiator.java:105)
        at org.hibernate.reactive.provider.service.NoJdbcEnvironmentInitiator$DialectBuilder.buildResolutionInfo(NoJdbcEnvironmentInitiator.java:83)

Just for completion, here is a document with a detailed explanation about how to add services in versions 5.3 and up: Hibernate ORM 5.3 Integration Guide