Version 6


    A major concern during the replication of stateful session beans and/or web sessions is preserving, upon deserialization, the identity of an object with many referants.  For example, a stateful session bean containing a reference to an extended persistence context (XPC) and a persisted entity must, upon realization on a remote node, preserve the object identity between the entity reference and the internal reference to that entity within the referenced entity manager.  Currently, this is achieved though monolithic serialization of the entire bean context, including referenced XPCs and entities.  Likewise, replication of a web session containing references to an entity and its XPC must use coarse, session-granularity replication.  These solutions concede the following inefficiencies:

    • Serialization of the entity manager involves the superfluous serialization of the session cache.
    • Persisted entities are serialized in their entirety, even if they contain no unflushed changes.

    Referenced JIRAs:


    We will address the inefficiencies listed above, by performing serialization, as defined by the OptimizedEntityAwareSerializationStrategy, within the EntityAwareMarshalledObject constructor in 3 steps, as represented by the properties of the EntityAwareSerializationContext:

    1. EntityAwareSerializationContext.getEntityManagers():
      • For SFSBs, this refers to the container's map of XPCs.
      • For web sessions, this refers to session attributes that are XPCs.
      • During entity manager serialization, we replace references to entities that do not contain unflushed changes with null.  This has the effect of compressing the session cache to contain only those entities that cannot be refreshed from the database.  This approach makes the assumption that 1st level cache access is done via get only, and never by iteration.
    2. EntityAwareSerializationContext.getEntityAwareObject():
      • For SFSBs, this refers to the bean context.
      • For web sessions, this refers to session attributes that are not entity managers.
      • During serialization, any entities that do not contain unflushed changes are replaced by an object (i.e. SerializedEntity) encapsulating the entity's identifier, class name, and persistence unit name.
    3. EntityAwareSerializationContext.getPlainObject():
      • For SFSBs, this refers to interceptors and nested bean contexts.
      • For web sessions, this returns null.
      • Serialize normally

    During deserialization, i.e. EntityAwareMarshalledObject.get(...), the corollary sequence occurs, to construct an EntityAwareSerializationContext:

    1. EntityAwareSerializationContext.getEntityManagers():
      • Deserialize normally - the resulting entity manager's session cache will only contain entities with unflushed changes.
    2. EntityAwareSerializationContext.getEntityAwareObject():
      • During deserialization, replace any instance of SerializedEntity with the corresponding entity fetched from its entity manager.
    3. EntityAwareSerializationContext.getPlainObject():
      • Deserialize normally



    Open issues:

    • Coordinate the replication of web and EJB layers, to preserve identity of shared object references across tiers.
    • Measure cost of HibernateEntityIntrospector.hasUnflushedChanges(...)