my first question is that WHETHER DOG CLASS IS SERIALIZABLE ? i say NO.
Correct your Dog is not serializable, so you can't let it implement the Serializable interface. You, as a developer, have made a mistake.
Of course there are ways to solve this, the obvious solution is to let the Collar implement the Serializable interface. However if that Collar object isn't serializable then there is the option to make the instance variable transient. This way the Dog can be serialized and the Collar object is skipped.
The thing to understand here is that if a class is not Serializable you can't migrate it. ( so
you should try to avoid having non-Serializable objects in your Session )
examples of non-Serializable classes are database-connections, streams, threads, runtime...
So what is the purpose of the HttpSessionActivationListener:
- cleaning up (closing) resources that can't be Serialized in the
sessionWillPassivate() method, and creating them in the
sessionDidActivate() method
- when you have a serializable class but the superclass isn't, then any instance variables you inherit from that superclass will have to be reset (in the
sessionDidActivate() method) to the values that were given during the original construction (remember: this is automatically done if
java serialization is used for Session migration, but if the container uses its own mechanism, you will have to do that yourself)
Regards,
Frits