views:

72

answers:

2

Choosing carefuly datatypes, finally a complex Class is created, then using a HashMap, those first Class objects get mapped with a key. and now I can create thousands and access them, add, delete, etc..

Now if I want to store them in a DB..

So I start from scratch? have to create the table?, again take care about datatypes? to make fit my objects inside the DB, furthermore I have to make a lot of function to "transform" data.. then SQL to make the queries..two languages, first to process, second to access data.. with this things I remember actual languages could be the punched cards of future ones.. (of course if I want a web interface I could have to think in a third one)

I think to use java persistense, but that's not a DB..

Are you doing this twice out there? any advices are welcome!

EDIT:

I have seen there are some tools as XStream or Simple to pass objects to XML (and vice versa), but well, of course XML is not a DB.

+4  A: 

This is exactly what object-relational mapping is for. It (usually) allows you to define only the Java classes, or only the DB schema, and generate one from the other, and have the "transformation" happen more or less automatically.

For Java, the Java Persistence API and Hibernate are the most common OR mapping tools.

Michael Borgwardt
+1  A: 

If you are wanting to map database rows to java objects, then there is a nice program I use that takes 0 configuration, just create a POJO with similar fields (you have to define it somewhere), and your done.

http://www.easierjava.com/

TheLQ