Hazelcast DataSerializable cannot be used with the Hibernate L2 cache, because the stored objects in the Hazalcast cluster are not objects of your object. Hibernate uses its own data format (e.g. serialization) in L2, converts your entities, their relationships and collections into its own format, and provides its own objects (implementing java.io.Serializable) for Hazelcast. Hazelcast serializes those that use standard Java serialization and distributes between clusters.
If your classes have a complex and deep graph of objects (heavy use of linked objects and 1xn or similar relationships), this double serialization problem causes long delays.
Hazelcast has nothing to do with Hibernate lazy-loading. Hibernate already stores entities and their relationships and collection collations separately. Thus, all of them can be downloaded from Hazelcast one by one. But in your use case, if most lazily loaded relationships are always loading, then this will cause several Hazelcast remote calls instead of one. Therefore, you should carefully consider where to use lazy loading.
Another trick is to use / activate Hazelcast next to the cache if your application is mostly read-only. (Btw, if it is not, then using the L2 cache may not suit you.) This way you will save a lot of remote calls, and often the necessary data will be cached locally. Near the cache, all Hazelcast card properties are supported, such as TTL, eviction, maximum size, etc.
Hazelcast close cache documentation ...
mmdogan
source share