How to get literals for StatementInspector

Hi there,

I’m using the StatementInspector to intercept the SQL being generated by Hibernate. I want the full SQL statement including the literals whereas at the moment I get

select p1_0.id,p1_0.created_at,p1_0.first_name,p1_0.last_name,p1_0.modified_at from person p1_0 where p1_0.id=?

…whereas I actually want

select p1_0.id,p1_0.created_at,p1_0.first_name,p1_0.last_name,p1_0.modified_at from person p1_0 where p1_0.id=1

It looks there’s a couple of Hibernate properties which might help here. Firstly, I tried in my HibernatePropertiesCustomizer I tried doing the following:

hibernateProperties.put(AvailableSettings.CRITERIA_VALUE_HANDLING_MODE, ValueHandlingMode.INLINE);
    hibernateProperties.put(AvailableSettings.STATEMENT_INSPECTOR, statementInspector);

…where statementInspector is my customized StatementInspector but the CRITERIA_VALUE_HANDLING_MODE appeared to have no effect. In Hibernate 5.3 there also appeared to be a property LiteralHandlingMode but it looks like this has been removed in 6.4.4.Final which is the version I’m using with Spring Boot.

Would be very grateful for any assistance with this.

Regards,

John

Why do you need the SQL queries generated by Hibernate? This is not the intended use of StatementInspector.

ValueHandlingMode.INLINE

Always inlining parameters into queries comes with a lot of limitations and disadvantages, and also opens up potential SQL Injection risks. Please tell us what you’re trying to achieve and we can figure out a better solution.

So I would like to capture the actual SQL string that’s executed against the DB. The idea is to create a bespoke CDC solution where I capture the SQL string being executed against a source DB, translate the SQL into the target database’s dialect and then send that SQL in the form of a command event across the wire where it will be executed against the target DB so that both databases stay in sync