0

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>
1

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you provide me an example, please?
Try using a datasource proxy (github.com/ttddyy/datasource-proxy). We used it and were able to parameter values etc
0

Use slf4j + Log4j

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version> <!-- Use the latest version instead -->
    </dependency>

log4j.properties

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO

# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL

hibernate.cfg.xml

<property name="show_sql">true</property>

Now parameters will be logged.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.