.NET Serialization: saving your object in a database... is this better than saving data in columns?

Posted on 2011-09-09
Medium Priority
Last Modified: 2012-06-27
Hi, I have a question... possibly a stupid question, I'm not sure.

But, just started dabbling with serialization because I've created a website which savesinformation related to the user. So, in order to work with this data, I extract the user's information from the database, put it into my User object and then perform manipulations.

But, ultimately the data is stored in a standard table in an oracle database. So, of course I've just realised and managed to get working, the process of saving that data in the oracle table (BLOB field) as a serialized object. Then I can extract that serialized object directly without having to extract the information column by column.

So... knowing little about this and not really being able to see the possible difficulties down the road... I am just wondering to myself... why bother storing the data in standard format at all? Why not just do away with all the columns and only store the User object?

So why not? Well, I guess the obvious answer is that you can't run simple queries on your database anymore... and you're going to want to do that. But, I am just wondering whether I'm better off, not only storing the data in a standard column, but then including a User column at the end where I store my User object also. Then I can more or less build my code around extracting that object when I want to deal with a user's information... instead of extracting every column and building my Task object column by column in code.

What do the experts say?! What's the standard way people do these types of things?
Question by:AidenA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 36509530
Well, depends - how big is your application, how many users you;ll store, how often you;ll need to search in... you name it.

Technically it is possible. But from architecture point of view - depends on many things.


Ivo Stoykov

Author Comment

ID: 36509553
what do you mean technically it's possible? I just tested and was able to store a user object in a blob along with all the other data and then extract it again. So... it's possible yes. But do companies generally do something like this... and if not, then why not?

There is a bit of overhead with serialization, so that might be a reason. But binary formatter is very fast, and I don't think it would affect things in my case. There will only be about 100 users using the site and not in with heavy usage either
LVL 22

Assisted Solution

by:Ivo Stoykov
Ivo Stoykov earned 200 total points
ID: 36509587
technically it's possible means
> ... able to store a user object in a blob along with all the other data and then extract it again.

> do companies generally do something like this... and if not, then why not?
Decision is made upon many considerations. You cannot just ask "to store or not to store?"
These are fundamental questions about database storage. Each decision has pro and cons and this is why some companies do other - don't.

The best answer for me is - test it, measure it and you'll get the answer.


Ivo Stoykov
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.


Author Comment

ID: 36509615
Yeah but that's not really a useful answer if you don't mind me saying so :(

Here is an answer... just saw this article


So based on that, I'd be inclined to say that it is a bad idea to store your objects in a serialized way. (1) As I mentioned, you can't run queries easily on it anymore (2) As the article mentions, if you need to make a small change to the data, this now requires a large change as the entire blob has to be updated... so there is loss of functionality here and loss of performance (although perhaps easier to code with).

If you were to include a blob with your object along with all the other data then in fact now it's worse because you'd have to make two updates if you wanted to change the data, one to the columns with the data and then to the blob with the object in it. So, that makes no sense (thinking about it now).

Where it makes sense is probably where I was thinking of using it in the first place, in fact. I have an ERROR table which contains some error information, and I wanted to include all the user information I have in a column along with the error information so I can have a better idea about what caused the error. In that case, I don't need to update the blobs, I don't need to run queries on the blobs... I just need to extract the information associated with the error as is. So, that's probably a good situation for it.

So, I don't know... that seems like a clearer analysis? Unless there's something wrong with the above...


Assisted Solution

jagrut_patel earned 800 total points
ID: 36509636
Whether to persist User object into DB depends on how costly you think is it to re-create the same object again?

In both cases Database trip is still there. If we consider volume of data transferred between the two approaches then I believe serialized blob of User object would be larger.

If re-creation of User object is expensive then how about storing it into Cache. Thus you can put logic that retrieves ready-made object from Cache and if required User object is not cached create it and put into Cache.
LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 1000 total points
ID: 36509923
My 2 cents:  

I would store it unserialized for many of the reasons you posted:  Ease of update and selectivity.

You also do not need to write a bunch of maintenance/migration code if the serialized object changes.

The 'R' in RDBMS is Relational.  If you are not going to take advantage of the power of a database, then why use one?  Let alone Oracle.  There are MUCH cheaper options at that point.

Author Comment

ID: 36510022
yeah thanks for that... i'll go with what i was going for initially then, just saving the object in a blob if all i want to do is store it and read it later as I do with the error table... in that situation it's quite useful...

thanks for input...


Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question