• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A general question about Hibernate

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

I am considering using Hibernate for a project, but I need to know something about its capabilities.

If you use java objects to create a schema, how smart is the schema update?
e.g if I change the name of a field in an object, will the table column name change? Or will the old column get dropped and a new unpopulated column be created?
Assuming annotations are used.

J.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off never use schema generation/update in production, that was never its intent. It is a development tool only. That said you can set the column name and the field names can be changed without affecting the column.



I can rename myField to whatever I want and the column name will remain the same.
 
John Farrel
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I guess the question is what's best practice for use of Hibernate;

Create the database and generate classes from it?
Create the classes and generate the db schema?

My gut feel is to generate classes from db.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess there are people from different camps on this. Personally I believe that one of the major advantages of using an ORM is the ability to focus on the Domain (object) relationships and not have to have those objects reflective of the relational (database) model. Therefore I typically start with creating my objects in a way that makes sense for my application. I can basically ignore the database at this stage. When I have that set up I put the relationships in and then if this is a new database, generate the schema and make tweaks as necessary.

For example if I have a person object and the person object contains an Address object I do not need to worry about whether the address details live in the same table as the other person properties or in its own 'ADDRESS' table. I can account for that with my mappings later. Also often times the database already exists. In this case the trick is usually mapping the existing relational model to my domain model. Not the other way around or you lose one of the biggest advantages of an ORM imo.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic