I was wondering what would happen, if I change a property of a DOM object retrieved from Hibernates second level cache. I found this quote:
2nd level cache stores a map of entities' IDs to other properties (it doesn't actually store objects, but the data itself)
user = userDao.find(1); // get user stored in second level cache
System.out.println(user.getName()); // returns "originalName"
// === this is done in a different session ===
user = userDao.find(1);
System.out.println(user.getName()); // should return "originalName"
Yes it is. The second level cache gives you a "copy" of the cached entity data.
The entity is not stored as-it-is. An entity must be dehydrated before being stored to the cache. When you load an entity from the cache, the entity is rehydrated back, so you always get a new copy of the dehydrated data.
As opposed to a java.util.concurrent.ConcurrentHashMap, the second level cache could be saved to the disk (meaning you always get a copy of the disk-based saved data), and so it must be consistent with both an in-memory and a disk-based 2nd level caching implementation.