• 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

multiple objects vs single object in session

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone !!

I have to store multiple objects in a session. These objects are related to each other and can be referenced inside a single object. I need experts opinion whether I create object graph, with reference other objects and store the parent object in the session or store all separate objects in session.

I would like to know, which option is better (storing multiple objects or a single reference object which contains reference to other objects) in a session.

Kindly advise on the same
 
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

I need experts opinion whether I create object graph, with reference other objects and store the parent object in the session or store all separate objects in session.


I would say that depends on how you want to manage these various objects. Do you always need all of them or can some be discarded when no longer needed.
I hope you are not storing references to objects like database connections that really should be managed elsewhere.
Do you need to do something with them when the session finally expires? If so a single object holding all the references and implementing HttpSessionListener is the way to go.
Bill
 
Pushparaj Deshmukh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William,

No I do not store database connection object. I store multiple DTO. Say One customer has three books.
1) I can store reference of list of books and customer separately in session or
2) Have the reference of list of books in customer and store single reference of customer in session.

I feel the second would be better. As server does not need to maintain so many instances in its memory.

Is it so?

Thanks.
 
Pushparaj Deshmukh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William,

No I do not store database connection object. I store multiple DTO. Say One customer has three books.
1) I can store reference of list of books and customer separately in session or
2) Have the reference of list of books in customer and store single reference of customer in session.

I feel the second would be better. As server does not need to maintain so many instances in its memory.

Is it so?

Thanks.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is really necessary to use session then it would be better to store a list of TOs.

I said like this because sometimes objects qualify for request and folks used to set those in session.

Cheers.
 
William Brogden
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

1) I can store reference of list of books and customer separately in session or
2) Have the reference of list of books in customer and store single reference of customer in session.

I feel the second would be better. As server does not need to maintain so many instances in its memory.



Recall that storing a reference in session does not create a new object, only a new reference - the same reference that would be stored in a customer object. Stop Worrying about minor differences in memory use - Instead worry about clarity and ease of maintaining the code. See my original post - what are the management requirements for these objects?

Bill

[ March 28, 2006: Message edited by: William Brogden ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic