• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need to store non serialized object in session as attributes

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am working with an J2EE application and i need to save some object (non serialized) into session as an attribute. This is not creating problem on Myeclipse but after hosting the application if after creating some session we change some java files then it throws exception something want to say that we should not store the non serialized object into persisted sessions and session got empty.

Is there any way to forcibly save the non serialized object into session as attribute without creating this type of problems.

Please help me on this.

Thank You.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on your app and your deployment.
If you're clustering with session replication, binding non-serializable objects to session will prevent replication from working.
Also if you need to be able to restart an application (or the container) without killing your users's session this could cause a problem as some containers (Tomcat for one) achieve this by serializing the whole session to disk when the app shuts down and then deserializes them when the app starts back up.
Also, if your container is storing session information in a database, it will need to be able to serialize them.

Why can't you implement Serializible?
What are you holding in these objects that can't be serialized?
 
Mohit Kumar Tayal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben,

Actually i have stored the connection object in session within another object that is to be stored but i have removed this object from that class now.
Thank for the help.

Now i need one more help. as you have said that it is vendor specific where it will store the session data either in file on disk or in database, is it possible that tomcat save context attributes as well somewhere and reload them on server startup like session attributes.

I need to store some data in context as well.

Thank You
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat does not persist context scoped objects.
 
Mohit Kumar Tayal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben,

Is there any alternative way to achieve this something by using context linstener and overriding method named contextinitialized and contextdestroyed.
I think this will solve the problem but is there any direct way to save the object to some file and again load from the file in java.

Thank You.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is there any direct way to save the object to some file and again load from the file in java.



Of course - make it Serializable, write it to disk and load it back whenever. Unless it is a really complicated object, you will be pleasantly surprised by how fast this is.

CAUTION: DO NOT do this with objects which should be managed by the container or which tie up system resources such as database connections.

Bill
 
Mohit Kumar Tayal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William,

You are right, i have achieved this by using file operations.

Thank You.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic