Hibernate SQL Logging to Log4j

In my projects, for logging the SQL statements generated by Hibernate I always set the hibernate.sql_show property to true in the hibernate.cfg.xml file:

 
<property name="hibernate.sql_show">true</property>

This logs the SQL statements to the STDOUT console. Only recently I realized that the logs can also be sent to Log4j. Of course this allows to log the SQL statements not only to the STDOUT but also to all possible Log4j appenders such as a file appender etc.. There are (at least) two ways to do this.

1) Setting the log level statically in the log4j.properties configuration file, e.g.:

log4j.logger.org.hibernate.SQL=DEBUG, FILE_APPENDER
log4j.additivity.org.hibernate.SQL=false

Setting additivity to false ensures that log messages aren't bubbled up to parent handlers.

2) Or setting the log level dynamically in Java, e.g.:

import org.apache.log4j.Logger;
import org.apache.log4j.Level;    
...
Logger log = Logger.getLogger("org.hibernate.SQL");    
log.setLevel(Level.DEBUG);

Original post: http://peter-on-java.blogspot.com/2012/04/hibernate-sql-logging-to-log4j.html

Tags orm

Fun with Oracle DB: ORA-00907

Following SQL select statement

 
select * from A a
where a.id in (select b.id from B b order by b.id)

leads to an error message:

 
> ORA-00907: missing right parenthesis 

Hm. I don't see anything missing... Ok, let's remove the order clause, as it is not really needed:

 
select * from A a
where a.id in (select b.id from B b)

No ORA-00907. I am not the only one having these troubles, see the blog post by oraclequirks.

Original post: http://peter-on-java.blogspot.com/2012/03/fun-with-oracle-db-ora-00907missing.html

Tags database