• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

POJO first, DB next or vice versa

Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)

author and cow tipper
Posts: 5009
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic