This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A general question about Hibernate

 
John Farrel
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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: 91
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic