Serializing an ArrayList to disk

I

Ike

If I serialize an ArrayList to disk, soes it also serialize the objects in
the ArrayList? And if so, why would I opt for using, say, Hibernate, to
persist an ArrayList, as opposed to just Serializing it ? Thanks, Ike
 
M

Matt Humphrey

Ike said:
If I serialize an ArrayList to disk, soes it also serialize the objects in
the ArrayList? And if so, why would I opt for using, say, Hibernate, to
persist an ArrayList, as opposed to just Serializing it ? Thanks, Ike

Serializing an ArrayList (or HashMap, etc) serializes everything reachable
from that starting point (not counting transients and objects already
serialized.) The resulting encoding (binary, XML, whatever) can easily be
stored and retrieved, but is difficult to work with--search, query, modify.
To do anything meaningful with it usually means you have to totally
deserialize it.

If all your system needs to do is to store and retrieve opaque objects,
that's ok--I've built a number of systems like that. However, Hibernate
(and other persistence tools) store object to a relational database in way
that makes the object structure visible and accessible to other relational
operations. You can search and manipulate the data as tables and then
reconsitute the revised objects. Just being able to perform relational
queries over the objects makes this technique worthwhile.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
V

VisionSet

Ike said:
If I serialize an ArrayList to disk, soes it also serialize the objects in
the ArrayList? And if so, why would I opt for using, say, Hibernate, to
persist an ArrayList, as opposed to just Serializing it ? Thanks, Ike

You should not use serialisation for anything other than short term, eg
streams. The risk is you lock your development to the time of that 1st
serialisation. There are ways to ease this, like declaring your own
serialUID and being aware of what you can change. But none are really
satisfactory since you don't have a crystal ball. Use Hibernate and/or
databases, and store more granular entities.
 
V

VisionSet

VisionSet said:
You should not use serialisation for anything other than short term, eg
streams. The risk is you lock your development to the time of that 1st
serialisation. There are ways to ease this, like declaring your own
serialUID and being aware of what you can change. But none are really
satisfactory since you don't have a crystal ball. Use Hibernate and/or
databases, and store more granular entities.

Of course, your usage may well be for short term persistence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top