aspose file tools*
The moose likes Object Relational Mapping and the fly likes POJO first, DB next or vice versa Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "POJO first, DB next or vice versa" Watch "POJO first, DB next or vice versa" New topic
Author

POJO first, DB next or vice versa

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Hi

I am very new to Hibernate. I did my 'Hello World' with a Netbeans tutorial which showed how to generate the POJOs and mapping files from the relational tables, which seemed very logical to me!

However now when I am reading more about it, the books mention that classes are written first, then mapping files and then the DB is created. I am slightly confused. Can someone please tell me which is correct approach (I mean, how is it done in real world)

Thanks
Abhishek
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

You're discussing some chicken and egg stuff.

In my experience, some database admin puts together an ERD and you have to map to it. The database person has no friggin' idea how to properly design a database, and it becomes a nightmare doing the mappings. So, on most projects I've been on, that's how it's been done.

For me, I'd ideally like to create an object model, and then just have the objects map to the database. If I'm 'first in' on a project, that's what I usually do, before any database people get their dirty little hands on the project and mess everything up.

Do I sound bitter?

If you're new to Hibernate, I'd be flattered if you checked out my tutorials. Here's a little tutorial that uses the SchemaExport class to have Hibernate map an object (User class) to a database. Hibernate creates all the underlying tables for you in this example, which is really neat.

Hibernate Top Down Mapping with the SchemaExport Class


-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: POJO first, DB next or vice versa