Hi I think I'm not getting about the use of serialized java beans, here is what's confusing me. If I understand correctly we can use JavaBeans to permenantlly store data (like a database)for example if I have a web app that stores info on employees I could hava an employee java bean. Each employee would have one file in a special directory. example: /employees/employeeID.ser I understand the mechanism of serialized java beans, I just wanted to know if it is a "good practice" to proceed this way. I mean, if you add a field to your employeeBean class then your existing serialized beans will be unusable (I think you get a InvalidCastException) so for me this technique is not really good if you need extensibility? If anyone has a view on this please let me know. I haven't done any real enteprise apps in java before so I could you someone else's experience Thanks in advance Dominic
Dominic, I really would not recomend this as a way to persist data for any length of time. The reasons are varied and numerous, a few are: a) If you ever change the implementation of the employee java bean, the previously serialised objects will no longer be unserialisable. You will get ClassCastExceptions all over the place. b) Serialization is a performance killer. You will have no caching (unless you write it yourself) etc. It would be much better to use a database to store your persistent information IMHO. Hope this helps Sam
<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Joined: Dec 13, 2002
I was wondering why is sun putting that in their objectives if it's an inefficient technique. Do you know any other uses for Serialized java beans or sould I just forget about them (after the exam ) Dominic
Joined: Jul 26, 2001
Originally posted by Dominic Paquette: I was wondering why is sun putting that in their objectives if it's an inefficient technique. Do you know any other uses for Serialized java beans or sould I just forget about them (after the exam ) Dominic
There are lots of uses for serialization in general. It is a powerful technique (and used internally by many app servers and databases) so it is well worth understanding it.
This month's JavaPro magazine has an interesting article that relates to this topic. Check out http://www.fawcette.com/javapro/2003_02/magazine/features/dsavarese/page2.asp Essentially, the advantage of serialization is that it's simple to do. The cons are that only Java programs can read the serialized objects, serialized objects can't be queried (like in SQL), and serialization is not good for storing a lot of information. It can be the right choice if you have a small amount of data and you want to avoid all the overhead and licensing fees associated with a relational database.
IBM 286, SCJP, SCWCD, EIEIO
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com