I have crearte log4j.properties file like below:
log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.appender.hb=org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout=org.apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n
log4j.appender.hb.Threshold=TRACE
Can someone help me to how to include it in hibernate.cfg.xml
file? I am sorry I actually don't know how log4j works. I create this to display my hibernate query with value
instead of ?
but still it displays ?
nothing changes so what I need to proceed further?
I took reference from here Hibernate show real SQL
In my case it wasn't hibernate.cfg.xml, it was log4j.xml file where I put the code given by @jdev
< property name="show_sql">true Shows SQL queries
< property name="format_sql">true Format the query shown on console
< property name="use_sql_comments">true comments will be added to the queries
If your project is having 1000s of queries printing to the console, make others false: < property name="show_sql">true < property name="format_sql">false < property name="use_sql_comments">false
OR write an appender to the log4j.xml which I have done in my project, just to write all SQL queries on separate text file which is specified here: Configuring Hibernate logging using Log4j XML config file?
i like sql logging with proxy of jdbcdslog much more than hibernate logging.
Log SQL that is communicated with the database
The 'show_sql' property in your hibernate.cfg.xml causes the queries to be printed directly to the console.
Log4j allows output to be logged anywhere from console to file to network ports to databases. But the simple configuration that you have is supposed to print on the console as well. So first remove the show_sql property to see if Log4j puts anything on the console at all.
If this doesn't work, it shows that Log4j is not configured correctly. If you're using hibernate > 3.5, it uses the slf4j api, which uses logback by default instead of log4j. You can easily switch to log4j by removing logback jar(s) from your classpath, and adding slf4j-log4j12.jar and log4j.jar instead.
The Log4j tracing also prints the queries using '?', but it also prints the parameter bindings, i.e. what the '?' will be replaced with by the database driver or server.
You can't print the values inline. Hibernate will always print the ? when logging the queries. The output of org.hibernate.type logging at the DEBUG level shows the values and types that are used to replace those question marks.
Please refer hibernate reference as per your version. Here is 3.3 Link
Edit :-
Enable following log 4j categories.
Add this also
your problem will be fixed.