Wednesday, January 21, 2009

Hibernate query logging with binded parameters

I've been struggling with Hibernate queries before. Now I took the time to research this and ended up with another fucked up situation in Java world. There really is no "best practice" AND easy way of capturing queries (HQL/SQL) that are executed on DB in Hibernate.

Basically there is these alternatives:

1. Hibernate built in options ( a good description here )
2. Use Jamon, P3Spy or another similar tool
3. Custom query translator for Hibernate ( see here )
4. SQL database general query log (if applicabel to your database)

Among these only P3Spy, Custom translator, and query log have the ability to display binded query parameters within the query. So that you can copy/paste the query to your SQL tool/terminal. P3Spy project is on ice and custom query translators don't really sound like "best practice". General query log depends on DB. And should you really be spending your time programming custom translators?

Not least but last: the methods above display ALL the queries executed! When using Hibernate built-in options the data flow is way too moch for a web page that has maybe 20 queries on page load.

So there is NO NICE way of debugging that one runaway query in Hibernate/JPA. This is just NOT ACCEPTABLE. We need to be able to turn debugging on/off in Java code when making queries. Heck, my custom built data layer in PHP has the ability!

No comments:

Post a Comment