Cacheable Result [email protected] is null Standard Query Cache - Query results were not found in cache select querycache0_as id1_1_, querycache0_.author_id as author_i4_1_, querycache0_.created_on as created_2_1_, querycache0_as name3_1_ from Post querycache0_ order by querycache0_.created_on desc limit 10 Standard Query Cache - Caching query results in region: org.hibernate.cache.internal.
Cacheable Result [email protected] value: [5872026465492992, 1] Jdbc Transaction - committed JDBC Connection ------------------------------------------------------------ Query Cache Test - Check get entity is cached Jdbc Transaction - committed JDBC Connection ------------------------------------------------------------ Query Cache Test - Check query is cached Standard Query Cache - Checking cached query results in region: org.hibernate.cache.internal.
Standard Query Cache Standard Query Cache - Checking query spaces are up-to-date: [Post] Ehcache General Data Region - key: Post Update Timestamps Cache - [Post] last update timestamp: 5872026465406976, result set timestamp: 5872026465492992 Standard Query Cache - Returning cached query results Jdbc Transaction - committed JDBC Connection If you enjoy reading this article, you might want to subscribe to my newsletter and get a discount for my book as well.
Hibernate is a very sophisticated OR-Mapper and as such has some overhead for certain usage patterns or raw queries.
Through proper usage of caches (hibernates featured a L1, L2 cache and a query cache) you can get both performance and convenience if everything fits together.
When trying to get more of our persistence layer we performed some tests with the query cache to be able to decide if it is worth using for us.
We were puzzled by the behaviour in our test case: Despite everything configured properly we never had any cache hits into our query cache using the following query-sequence: would be a cache hit but in our case it was not.
Session [email protected]] for Hibernate transactionorg.hibernate3. Hibernate Transaction Manager - Preparing JDBC Connection of Hibernate Session [org. Hibernate Transaction Manager - Found thread-bound Session [org. Session Impl - opened session at timestamp: 5927941831806976org.hibernate3. Two Phase Load - resolving associations for [system.entity. Two Phase Load - done materializing entity [system.entity. Stateful Persistence Context - initializing non-lazy collectionsorg.hibernate3. Update Timestamps Cache - Pre-invalidating space [demo1_code_generate]org. Abstract Batcher - about to close Prepared Statement (open Prepared Statements: 1, globally: 1)org.hibernate.transaction. Connection Manager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources! Update Timestamps Cache - Invalidating space [demo1_code_generate], timestamp: 5927941833535488org.hibernate3. use Unicode=true&character Encoding=UTF-8, User [email protected], My SQL Connector Java]2015-11-11 : DEBUG main org.hibernate3.
Session [email protected]] for Hibernate transactionorg.hibernate3. Hibernate Transaction Manager - Opened new Session [org. Hibernate Template - Not closing pre-bound Hibernate Session after Hibernate Templateorg.hibernate3. JDBCTransaction - re-enabling autocommitorg.hibernate.transaction. Hibernate Transaction Manager - Closing Hibernate Session [org. Hibernate Template - Found thread-bound Session for Hibernate Template2015-11-11 : DEBUG main org.
Query caches are useful if you want to cache the result of a HQL or criteria query.
But be careful if you are using query caches and native queries.
Hibernate’s second level cache is used to cache domain objects and queries.