Hi all,
I'm writing an application that has some pretty demanding use. As such I've designed the Hibernate mappings to minimise the number of queries needed against the database per-operation.
For example, loading an entity with a collection. I want an eager fetch on the collection because I know, 100% of the time, that I'll need to walk over the collection elements. As such I want one query using an outer join on the database, instead of n+1 queries (if it were lazily loaded). I can verify it by logging out the SQL and checking that I have exactly one query, and the query makes sense manually (ie, no pointless joins). But manual testing sucks, and later on, other devs (or even myself) might forget about it and cause problems. I want to automate!
Has anyone done something similar and can share some tips on how to do this? The sort of things I might want to do are to count the number of queries executed against the database per session, and possibly do some regex matching on the queries as well.
I feel like I need some event or callback handler that gives me the SQL each time it gets generated, or captures the SQL and gives me the list of executed statements after the session is closed. I suppose I could write a custom log implementation and pass that into SLF4J, but that sounds like a bit of messing around to write and integrate.
Cheers, Jason
|