File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Serialization" Watch "Serialization" New topic
Author

Serialization

jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
can anyone say why do we need to go for serialization for persistent storage when we have database
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I assume by serialization you are refering to serializing objects to the file system. Databases are a better persistent store because:
  • they are transactional
  • they support multiple users
  • they are accessable to other applications, not just Java
  • they can ensure data integrity via constraints
  • they are accessable from environments that can't access the file system, such as an EJB container
  • your data is not going to become invalid when you update the class you serialized from (unless you are specifying a serialVersionId)

  • and there are probably other reasons.


    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    jeff rusty
    Ranch Hand

    Joined: Nov 07, 2006
    Posts: 109
    ya i got that .. but i want to know why sould we use Serialized objects (Implements serializable)when we have database

    thanks in advance
    Prem
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    If we are still only talking about serialization as it pertains to persisting an object on the file system (and not serialization in the context of distributed programming, i.e. when we need it to send objects between JVMs), I suppose when the overhead of a database is too much for the requirements of a particular application. If, for example, the application is a simple, single user desktop application why would we need the overhead of a database?
    Cameron Wallace McKenzie
    author and cow tipper
    Saloon Keeper

    Joined: Aug 26, 2006
    Posts: 4968
        
        1

    Serializable - the breakfast interface. Making sure we can pour milk over our JavaBeans and have them for breakfast.

    Serialization is used not only to store object state to a filesystem, but also to send object state across a network. That's one of the reasons networking in Java is just as easy as interacting with a file system.

    So, in a clustered environment, you may read a user object in from a database, but the clustered JVM might have to do workload management on the user object - maybe make it available to sessions running on different JVMs. If the object is serializable, then the JVM will be able to pass that Java object around like yesterdays newspaper. If it's not serializable, there will be problems.

    That's just one, sorta hidden reason, on why it's important to make sure all JavaBeans are serializable.
    jeff rusty
    Ranch Hand

    Joined: Nov 07, 2006
    Posts: 109
    I am not clear. please explain in detail
    Purushoth Thambu
    Ranch Hand

    Joined: May 24, 2003
    Posts: 425
    This link will help on why serialize?
    http://en.wikipedia.org/wiki/Serialization
     
    jQuery in Action, 2nd edition
     
    subject: Serialization