![]() Therefore, we strongly recommend enabling a second-level cache for such entities. As is the case with collections, only the ids of entities returned as a result of a cacheable query are cached.Here are a some guidelines and best practices related to query caching: Native select queries don't invalidate the cache. Note that the above applies only to DML statements ( insert, update, delete, and native function/procedure calls). We have to fall back to Hibernate native SQLQuery API, as this feature isn't yet defined in JPA. NativeQuery.unwrap().addSynchronizedEntit圜lass(Foo.class) ![]() The solution is to tell Hibernate which entities are affected by native DML statements, so that it can evict only the entries related to Foo entities: Query nativeQuery = entityManager.createNativeQuery("update FOO set. However, when it comes to native SQL DML statements, Hibernate can't guess what's being updated, so it invalidates the entire second level cache: session.createNativeQuery("update FOO set … where …").executeUpdate() In this case, all Foo instances are evicted from the L2 cache, while the other cached content remains unchanged. When it comes to DML-style HQL ( insert, update and delete HQL statements), Hibernate is able to determine which entities are affected by such operations: entityManager.createQuery("update Foo set … where …").executeUpdate() A change in a cached entity is either committed or rolled back in both the database and cache in the same XA transaction.
0 Comments
Leave a Reply. |