aspose file tools*
The moose likes Servlets and the fly likes Servlets , POJOs and Framework design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets , POJOs and Framework design" Watch "Servlets , POJOs and Framework design" New topic
Author

Servlets , POJOs and Framework design

Richard Corbin
Greenhorn

Joined: Nov 22, 2008
Posts: 12
Hi all,

I've been working on a framework for sometime now (OortCloud) that deals with mapping, wiring and filtering Objects to UI components. I recently read a few posts here at the O'l JavaRanch and it raised a few questions that I cant seem to answer through research.

Mainly:
Why must I Serialize every Pojo that will be used as a session scoped object throughout the framework? I mean I've read that it's a rule to do so, but... why? The way I have it now is to distribute these objects through a singleton (Enum factories which are already serialized) creating new instances of defined Objects when requested by a new session. Then I store said instances in a SessionBean container (also serialized) . When one SessionObject needs another I pull it from the Session Container. The only answer I can think of is in the event that the container is sent to another VM?

--Richard
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Richard,

first welcome to the JavaRanch

I think your last statement is exactly one main reason to make session scoped objects serializable! If you're working in a clustered environment with multiple servlet containers or application servers running in different JVM (probably on different machines) it's likely that session scoped data are migrated/replicated to other nodes because every container should of course see identical session data.

Marco
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Another reason.

Containers like Tomcat will serialize and deserialize session objects when an application stopped/start or restarted. This allows you to reload the application without kicking everyone out.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Richard Corbin
Greenhorn

Joined: Nov 22, 2008
Posts: 12


So in the above case where there is a container for these Objects (OBJMAP) which resides in a serialized object. would all of the objects in that map be serialized when the VM is restarted automagic like?
[ December 02, 2008: Message edited by: Richard Corbin ]
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Richard,

I'm not sure if I understood you correctly, so please tell me if I got it wrong

If something should be serialized by the container or any other framework or API it's usually the entire object graph which gets automatically serialized. So in your example it's not only the map itself which is serialized but also its content, i.e. the objects you have put in it. Strictly speaking the JVM _TRIES_ to serialize the whole object graph. But for this to work correctly each object/class down the nested object tree has to be serializable! Often this is not a problem if your own classes are composed of primitive types or JDK classes which are serializable but in general it's not sufficient to put an object in another serializable object in order to make this object serializable, too. I hope this explanation was understandable

Marco
Richard Corbin
Greenhorn

Joined: Nov 22, 2008
Posts: 12
Thanks Marco!

I started reading up on Serialization and I (Think I) get it now. I was under a few misconceptions about Serialization in general. Thinking that an object that was cast as an inner Class of a serialized Object inherited its serialization. when I asked this question over at
(sun.com java forums) I got a confusing response, and the usual catty quip that is pleasantly absent here at JavaRanch

Thanks again all!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets , POJOs and Framework design