1
votes

As we all know, it's possible to use the Hibernate cache for entities used in subsequent queries. My question is, are such cached entities immutable for changes after they putting in cache that way:

a) load the entities from the DB

b) while annotated cacheable, Hibernate put these entities in cache

c) the DAO receives the loaded object

d) the DAO manipulate some attributes of that entity (say decrypt some encrypted fields) but mark that changes as "non-relevant-for-cache"

e) for subsequent queries, the always cached -and manipulated- entities are returned by the Hibernate cache.

I hope this wishlist is not to naive, but I assume, these are quite normal requirements for modern apps based on Spring/Hibernate.

1

1 Answers

0
votes

The second-level cache doesn't contain entities. It contains rows of data as loaded from the database table by Hibernate. Each time an entity is loaded from the cache, a new instance of the entity is constructed from the data in the cache, as if it came from the database.

Transient fields of your entities are not stored in the cache.