JQL-Update Queries fails with activated L2-Cache

Type: BugPriority: CriticalStatus: ClosedReplies: 1
#1

When using JQL-Update Queries it is basically not working without calling entityManager.clear() after a transaction commit. When the clear() method isn't called the entityManager will never return a container the updated Entities.

Scenario 1: Disabled L2 Cache, updating elements using UPDATE-Query and fetching Entities afterwards from database.
Expected result: Getting changed Entities from database - Actual result: No changes are visble.

Scenario 2: Disabled L2 Cache, updating elements using UPDATE-Query, calling entityManger.clear() and fetching Entities afterwards from database.
Expected result: Getting changed Entities from database - Actual result: Everything ok, but it is quite a mystery why ".clear()" has to be called.

Scenario 3: Enabled L2 Cache, updating elements using UPDATE-Query and fetching Entities afterwards from database.
Expected result: Getting changed Entities from database - Actual result: No changes are visble.

Scenario 4: Enabled L2 Cache, updating elements using UPDATE-Query, calling entityManger.clear() and fetching Entities afterwards from database.
Expected result: Getting changed Entities from database - Actual result: Only one Entity has been updated, the rest has its old value. And here it is the same - its not really comprehensible why a call of ".clear()" is required to get at least a little bit better (but obivously not correct) result.

text/x-java iconEntityBulkUpdateTest.java (2.60KB)
Main entry point of sample application
#2

Apparently this is the expected behavior, as indicated on the UPDATE query manual page:

Updating entity objects in the database using an UPDATE query may be slightly more efficient than retrieving entity objects and then updating them, but it should be used cautiously because bypassing the EntityManager may break its synchronization with the database. For example, the EntityManager may not be aware that a cached entity object in its persistence context has been modified by an UPDATE query.

By using clear, you clear all cached objects from the EntityManager cache (the persistence context). But if the data is also cached in the L2 cache it may not help. Use refresh to enforce bypassing the L2 cache, or clear the L2 cache explicitly.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login