Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization

 
jeff rusty
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone say why do we need to go for serialization for persistent storage when we have database
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    jeff rusty
    Ranch Hand
    Posts: 109
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 4968
    1
    Hibernate Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 109
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am not clear. please explain in detail
     
    Purushoth Thambu
    Ranch Hand
    Posts: 425
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This link will help on why serialize?
    http://en.wikipedia.org/wiki/Serialization
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic