Friday, August 28, 2009

Logging parameters for Hibernate's SQL statements

I spent a little time solving a problem this morning that I had previously solved a month or two ago, so I thought I should write down the solution!

It is often handy to see the exact SQL queries that Hibernate produces when it is interacting with the database. In order for the queries to be logged, the log4j.properties file is modified such that the log4j.logger.org.hibernate.SQL property is set to 'debug'. The problem is that while the queries themselves are logged correctly, the queries' parameters are not displayed at all.

There is a log4j.logger.org.hibernate.type property in the same file, however setting its value to 'debug' does not work. The solution is to set this property to 'trace', and then the parameters will be logged after the query itself has been logged.

Tuesday, August 25, 2009

Bash Completion + Java

I think the title says it all, I was just checking something at work and needed to run one of our Java apps using the command line, I did the standard:
java -cp jarfile1.jar:jarfile2.jar au.gov.


and hit tab key twice out of habit and to my surprise bash had checked the jar files inside the command I was writing and presented me with all the class options!!

Bash auto completion just continues to impress me! Thank you bash, you have just made my life SO much easier yet again.

For those of you who have no idea what bash is, its a terminal shell used by default in Linux.. so for those of you out there not yet using Linux, here is yet another reason to do so.

OSX also uses bash as the default shell for the terminal, so I'll now have to test it on my macbook.. after a quick test the answer is no, OSX is either using an older version of bash which doesn't support this feature, or hasn't turned on/set up all the autocompletion features by default.