You can also do this using Proxool.
Just configure Proxool as your JDBC driver (the same way you do for P6Spy) then switch on statement tracing
(*) .
It actually works even better for me than P6Spy because:
* It's not a dead project like P6Spy
* It uses the default Log4J hierarchy and configuration mechanisms (P6Spy is usually awkward to integrate with the rest of your logging strategy)
It might not be as good as P6Spy for your own situation though because I'm not sure how well Proxool operates as a datasource inside an application server. But I only need it during my development testing, so it works well for me.
(*) I found configuring Hibernate with Proxool to be astonishingly painful (I found the same thing when I was using it with Hibernate a couple of years ago too - so no progress there). It's kind of cool once you get it working, but getting it to that point hurts (not just telling hibernate to use proxool and then telling proxool about my JDBC driver, but also being able to configure statement tracing to actually be switched on).
I found this page very helpful:
http://hibernate.org/222.html