Search code examples
hibernatejpalog4jlog4jdbc

how to log hibernate parameters


I have project pf JPA. My logs looks like this:

Hibernate: insert into TEST(DESCRIPTION, NAME, version, id) values (?, ?, ?, ?)
[08/12/14 06:26:26:026 GET] TRACE sql.BasicBinder: binding parameter [1] as [VARCHAR] - [desc]
[08/12/14 06:26:26:026 GET] TRACE sql.BasicBinder: binding parameter [2] as [VARCHAR] - [name]
[08/12/14 06:26:26:026 GET] TRACE sql.BasicBinder: binding parameter [3] as [INTEGER] - [0]
[08/12/14 06:26:26:026 GET] TRACE sql.BasicBinder: binding parameter [4] as [BIGINT] - [21]

I have trace of org.hibernate.type in log4j configuration. That's nice, but is there any way to write this type of output?

Hibernate: insert into TEST(DESCRIPTION, NAME, version, id) values (desc, name, 0, 21)

I was searching that in google, I can't manage to find this type of solution. This output looks readable, and easy to read log files. Why this does not have hibenrate?

My configuration is like that:

<category name="org.hibernate.type">
    <priority value="trace" />
</category>

Solution

  • I doubt this could be possible out of the box from Hibernate. You could explicitly proxy the connection, statement and prepared statements that are created by your application (using a decorator design pattern) and log the parameters that passed.