Jean-François Savard
Jean-François Savard

Reputation: 21004

Serialization problems using HazelCast with session scoped bean

Infrastructure

Context

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

Upvotes: 3

Views: 710

Answers (1)

faissalb
faissalb

Reputation: 1749

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.

Upvotes: 1

Related Questions