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
Matt Humphrey - 18 May 2006 22:04 GMT
> 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 matth@ivizNOSPAM.com http://www.iviz.com/
VisionSet - 18 May 2006 22:23 GMT
> 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.
--
Mike W
VisionSet - 18 May 2006 23:22 GMT
> > 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
[quoted text clipped - 6 lines]
> 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.
--
Mike W