Let's say we have a web application backed by a servlet engine/container like Tomcat. A user logs in. The database record for that user (represented by an instance of class User, let's say) is loaded, and we can store this as a session attribute with the key "currentUser", set it once, and use it to handle subsequent requests. In addition, we put more objects in the session attribute. Pretty basic stuff.
Now, if we need to deploy some new code and reboot Tomcat... The user sessions are still intact after reboot (restored from disk/db) as long as we don't change any of the classes whose instances are stored in the user session. But this is a big problem. I don't want users losing their sessions on new code release.
To get around this problem, I suppose that I can store in the session object only instances of classes that are assumed to not ever change (like storing the logged-in user's ID as an Integer as opposed to an instance of the User class). Then I'd never run into a problem of not being able to deserialize the session object upon reboot. But this makes things slightly more complicated as now I have to use the ID to load the actual object from the database, etc (and with caching, performance hit is not really an issue).
Is this what's typically done to get around this issue?