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

Posted on 2011-09-09
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
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 50 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.


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 200 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 250 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

733 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