Replies: 1 comment
-
It seems as though our issue may be related to the use of native SQL queries in conjunction with L2 caches. Apparently Hibernate, by default, invalidates all caches when a native update or delete query is executed. Obviously if the cache is emptied, Hibernate will need to reload entities from the database. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
As mentioned in some earlier threads, my project is using Infinispan 12.1.7 as an L2 cache provider for Hibernate 5.4.18. We have observed that application performance sometimes degrades to the point where it is consistent with an empty or disabled L2 cache.
Based on profiling results, it appears that
DefaultLoadEventListener#loadFromDatasource()
is being called for entities that we expect to be in the cache. This is apparently due toloadFromSecondLevelCache()
returningnull
:https://github.com/hibernate/hibernate-orm/blob/5.4/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java#L528
It seems that ultimately
loadFromSecondLevelCache()
delegates toCachedDomainDataAccess#get()
to retrieve a value. According to the Javadoc for this method, it returns "the cached data or null":https://github.com/hibernate/hibernate-orm/blob/5.4/hibernate-core/src/main/java/org/hibernate/cache/spi/access/CachedDomainDataAccess.java#L59
The implication is that
null
is returned when an entity is not found in the cache. However, I have noticed thatnull
is also returned under other circumstances, as noted in the comments here:https://github.com/hibernate/hibernate-orm/blob/5.4/hibernate-core/src/main/java/org/hibernate/cache/spi/support/AbstractReadWriteAccess.java#L65
Specifically, if an entity is in the cache but is "locked",
null
will be returned. I am wondering if this could be the source of the issue we are seeing. Under what circumstances might an entity become locked? If one or more entities are locked for a significant amount of time, it could conceivably cause Hibernate to load them from the DB more often than necessary.However, I could be misunderstanding the code. Would appreciate any thoughts/insights on this.
Thank you,
Greg
Beta Was this translation helpful? Give feedback.
All reactions