Solved

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

Posted on 2011-09-09
7
317 Views
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?
0
Comment
Question by:AidenA
7 Comments
 
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.

HTH

Ivo Stoykov
0
 

Author Comment

by:AidenA
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
0
 
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.

HTH

Ivo Stoykov
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:AidenA
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

http://www.mysqlperformanceblog.com/2010/01/21/when-should-you-store-serialized-objects-in-the-database/

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...

0
 
LVL 8

Assisted Solution

by:jagrut_patel
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.
0
 
LVL 76

Accepted Solution

by:
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.
0
 

Author Comment

by:AidenA
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...

Aiden
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now