views:

199

answers:

3

Here's the situation. I have a bunch of objects that implement Serializable that I want to store in a SQL database. I have two questions

  1. Is there a way to serialize the object directly into the database
  2. Is that the best way to do it or should I
    1. Write the object out to a formatting String and put it in the database that way and then parse it back out
    2. Write each member to the database with a field that is unique to each object
A: 

You could store the objects directly using db4o:

http://www.db4o.com/Android/default.aspx

Shane Cusson
This is a very cool project! I spent the whole evening playing with it and it works well, but it's just too slow for mobile apps!
CaseyB
A: 

Its generally not a good idea to try and put any sort of object (serialized/deliminated) in your SQL because modifying them is always a bitch.

It sounds like you're on the right track with idea 2. Is this a one-to-many situation? (because then a xref would obviously be the right answer) or even a foreign key would be better. cheers.

Jason
A: 

I'd still have a table per class + simplistic DAO.
If you absolutely want to do it wrong :), then serialize to JSON and persist the resulting string.

alex