Only objects that go into the session need to be serializable (i.e. Implement that Serializable
interface)
That means any object that is set as an attribute, plus any objects that are contained inside those objects.
So if you have a class
public class User implements Serializable {
private Department department;
// ...
}
then your Department
class also needs to implement Serializable
Classes that simple make calls on the session (include calls to setAttribute
) do not need to implement Serializable
(that includes SomeUtilityClass
)
The reason is that anything that is inside the session has to be sent to the other WebLogic node (that is probably running on a different server). That means that it needs to send your User
class over the network, so it needs to be able to turn your User
class into a series of bytes, that it can send, and then turn it back into a real object again on the other side.
When you implement the Serializable
interface you're telling Java that you've built your class in a way that it's OK for it to turn in into those bytes, (and back again). If you don't implement Serializable
then Java doesn't know whether it OK to do that, so it doesn't.
Note: The code for the class isn't being sent around, just the values of the fields inside it. The code is already on the other node, because it's part of your application that is already deployed to all nodes already.
Your utility class, doesn't need to go over the network. You haven't put an object of that class into the session, so WebLogic doesn't need to turn it into bytes (and back again_) as part of session replication.
The only things that need to be Serializable
are the objects that get put into the session either directly (like your User
) or indirectly (like the Department
example).
Objects that simply make calls on the session do not need to be Serializable
.