First level cache in hibernate is maintained on session object and within the boundary of same JVM. It is a mandatory cache that is used by hibernate. I am worried about it as how I will manage the it in clustered environment. Multiple nodes will have their own first level caches (equal to the number of sessions). At a single JVM, one entity can be a part of different session but transaction manager, optimistic locking handle the situation.... But how will we manage the it in clustered environment
1) an entity can be modified in the first level cache of two different nodes causing stale data issue, data lost issues.
2) If we use optimistic locking.... it will be hard to recover the transaction and also it can affect other usefull transactions on other nodes.
3) We can not take pessimistic lock for each and every transaction. It will kill the usefullness of hibernate caching.
4) Setup of Isolation level also will not work as transaction management is done by the hibernate application itself and boundaries of transaction management is one JVM.