Serialization problems using HazelCast with session scoped bean

701 Views Asked by At

Infrastructure

  • JSF 2.1.17 (Mojarra)
  • Hazelcast 3.3
  • JBoss EAP 6.3

Context

  • Session scoped bean named Login which contain one field email.
  • When deploying without Hazelcast, the bean is only instantiated one time and keep its values.
  • When adding Hazelcast to the application, we've noticed that the Login bean is deserialized at each execution phase (the memory address change, and the set email is not kept).

How we noticed

The login page was throwing "fields are empty" message while they were actually set. We then debugged more into this and found out that the bean is re-instantiated at each phase (using a PhaseListener).

Note that if we change the bean scope to request or view, the fields will be recognized, but it is not an option in the actual context.

Is Hazelcast overriding the way JSF handle session scoped bean ? If not, why is this happening ?

Edit : The bean does implement Serializable

1

There are 1 best solutions below

0
On BEST ANSWER

TL;DR

Add this init param to Hazelcast web filter :

<init-param>
    <param-name>deferred-write</param-name>
    <param-value>true</param-value>
</init-param>

You should be aware when you use Hazelcast session replication with JSF that every time ELResolver try to get a reference to a session bean Hazelcast will deserialized it for him. This is why your Login bean is being deserialized at each execution phase.

However Hazelcast WebFilter have a parameter called "deferred-write" that if set to true will cache the instance into a local map and give it to you directly from there. and at the end of every http request WebFilter will write all values stored on this map to Hazelcast.