Given all the smarts around Hibernate and it's various caching strategies, how do I know if a certain operation is resulting in a physical database hit, or coming from the cache?
Traditionally, you'll use Hibernate built-in cache logging and do some profiling during development to tune the whole thing until you get the expected behavior. To activate the cache logging, alter the log level, for example when using a log4j.xml
:
<logger name="org.hibernate.cache">
<level value="DEBUG" />
</logger>
Note that I do not recommend using this on the production platform (it may be very verbose and thus may slow down the execution).
For more details, refer to the Logging of the documentation.
I'm not really sure, but I'd try turning up the logging level of the org.hibernate loggers and see if that information is logged (it's most likely at the "debug" or lower level).
Hibernate Statistics should tell you all you need to know:
Enabling: Hibernate Core Reference
Using: Hibernate: Use Hibernate Statistics When Optimizing Queries