Java, what is a straightforward, simple method for persisting an object? Do all methods require serialization?

Unfortunately, "simple" and "straightforward" doesn't mix well with "SQL" or "database" in general. Java collection types just don't map easily to sets or documents.

Unfortunately, "simple" and "straightforward" doesn't mix well with "SQL" or "database" in general. Java collection types just don't map easily to sets or documents. The "correct" solution (as far as SQL is concerned) is to create a table for the list elements, then a table for the inner map (Integer -> List) and one for the outer map.

If your structure contains more than a couple of elements, you're not going to like the performance of this. So the other solution is a BLOB column and the Serializable interface. This has other issues like: You always have to load the whole structure all elements in the structure must be serializable if you can't load one piece, you can't load anything, etc).

If you want to add objects to the structure which are mapped to tables via you need some hacks to convert the instance to its primary key and back during save and load. You should consider an OO database like db4o which can save any Java object but you will need a different mindset when you write your code: Suddenly, you will need to think about things like running db4o queries on Java collections.

Thanks for the info, basically its an issue of speed as I am using a server with a lot of memory (+30gb) and want to keep all of the data I need to search within memory so having it in the mysql as a regular table just makes me have to convert it back and forth from the object format to the SQL. Anyways, db4o sounds interesting, I will definitely check it out. Thanks – Rick Mar 21 at 15:13 If you have enough RAM to keep the whole DB in RAM all the time, consider using an in-memory database (en.wikipedia.Org/wiki/In-memory_database) – Aaron Digulla Mar 22 at 9:55.

Whenever your persisting a object into DB, you need to Serialize that object.

Look at object databases like NeoDatis or db4o. They offer pretty straightforward way to persist objects. Personally I have used NeoDatis and I didn't need to implement Serializable interface or anything similar.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions