Greetings,

I think that you might want to separate your functional concerns into different objects.

One common pattern in multi-level architectures is to have a model object like Customer which would contain domain information for the Customer and a Service object like CustomerService which would be a singleton (many times injected using some IoC container). CustomerService would be used as a fascade to retrieve and persist Customer objects (or rather would delegate to a DAO layer to do the actual retrieval and persistence). The DataSource is usually injected into the DAO layer using your IoC container.

Spring is a popular IoC container which is used to manage the middle tier (and web tier if you like).

By separating the layers, you could persist Customer to the session and collaborate with the CustomService object and MessageResources when necessary in the web tier and avoid the NotSerializableExceptions you are running into with the DataSource and MessageSources. These are often interfaces whose implementations are provided by some framework, so it's unlikely you will be able to easily make them Serializable (they probably weren't meant to be anyways).


Keep in mind, there are many ways to implement multilevel architecture. You may want to do some research on best practices. Spring and Rod Johnson are good resources. You could also reference Martin Fowler.

Good luck.

/robert

----- Original Message ----- From: "abhishek jain" <abhishek.netj...@gmail.com>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Wednesday, July 14, 2010 5:15 AM
Subject: Re: Session error while loading an object


2010/7/14 Paweł Wielgus <poulw...@gmail.com>

Hi all,
You get this error every time when tomcat tries to save someone's
session and object of class com.cart.Customer is in it.
Like Robert said, add Serializable to com.cart.Customer and the
problem will go away.

Best greetings,
Paweł Wielgus.


Hi,
I have added the Serializable to com.cart.Customer, but now i am getting the
following error, which i think is due to the reason that i am using
reference of Datasource and Message Resource in the class which i believe is
not serializable:

IOException while loading persisted sessions: java.io.WriteAbortedException:
writing aborted; java.io.NotSerializableException:
org.apache.commons.dbcp.BasicDataSourcejava.io.WriteAbortedException:
writing aborted; java.io.NotSerializableException:
org.apache.commons.dbcp.BasicDataSource
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333)
      at
java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
      at
java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
      at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)


.....................

Pl. advice

thanks
abhishek


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to