|
The SessionFactoryImpl constructor builds the cache entity regions before registering itself using SessionFactoryRegistry#INSTANCE#addSessionFactory. This can cause problems if the cache is a clustered cache and entities with a composite ID are replicated.
IIUC, when an entity region is built by InfinispanRegionFactory#buildEntityRegion for a clustered, replicated cache, then the entities are actually replicated in the process of building the new EntityRegion.
If the entities being replicated to the new EntityRegion have a composite ID and the cache key contains the ID type [1], then, while deserializing the cache key, Hibernate will attempt to resolve the ComponentType in the cache key. Since ComponentType which has a field, typeScope, that has a reference to SessionFactoryImpl, SessionFactoryImpl#readResolve will be called. Because the SessionFactoryImpl has not been added to SessionFactoryRegistry.INSTANCE yet, the SessionFactoryImpl cannot be found. As a result, java.io.InvalidObjectException is thrown.
ComponentType#typeSope is not actually used and could be removed. This would fix replication of entities with composite keys, unless the composite key contains a *-to-one association. This is because EntityType also has a field, typeScope, that has a reference to SessionFactoryImpl,
[1] CacheKey instances in 4.2, 4.3 and cache keys generated by DefaultCacheKeysFactory#createEntityKey in 5.0 contain the ID type.
|