• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New Hibernate project: use separate DB create script or generate from OM?

 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After diving in some Spring and Hibernate tutorials, I feel ready to start with my first bigger Hibernate project, which is a website for creating and subscribing to in- and outdoor events by and for members.

With former (PHP) projects, I first designed a database, created the schema, started with some dummy data and builded the application around it.
Using Hibernate, the object model (OM) is already defined in the XML files or annotated classed, and the SQL schema can be generated from this OM.
When creating a separate DB create script apart from Hibernate, we introduce a redundancy and the DB schema and OM must be updated separately.

I cannot find much about best practices here. Should I forget about a separate DDL script and always generate the (modified) script from my OM? This also means that I must design the OM first and the DDL is derived from this OM.
I think this boils down to the question which should be leading, the OM or the DDL schema.
Any ideas are very welcome

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never used the possibility of generating the database script using the ORM. I always manually create the necessary DDL (and DML) scripts and execute them manually. My JPA entities don't have any annotation required to generate the database script (besides the column names of course )
 
Klaas van Gelder
Ranch Hand
Posts: 111
Java Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:I have never used the possibility of generating the database script using the ORM. I always manually create the necessary DDL (and DML) scripts and execute them manually. My JPA entities don't have any annotation required to generate the database script (besides the column names of course )


Thanks for your answer, I think that makes sense. My biggest point is that maintaining the OM and the DB create script completely separately is in fact a violation of the DRY principle. But on the other hand, the DM can not be completely derived from the OM because different kinds of mapping are possible.
So you suggest designing the OM according to the business domain and designing/creating the DDL script separately (but of course with the OM in mind) ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Klaas van Gelder wrote:So you suggest designing the OM according to the business domain and designing/creating the DDL script separately (but of course with the OM in mind) ?

It's not really a suggestion, but just what I always have done until now. Although I used an OM (always Hibernate) in almost every project for querying databases, I never used its capabilities to generate the database scheme.

I always manually create the tables as the 1st step, without keeping the OM in mind. I'm always trying to end up with a normalized database. If your database is normalized, you will not experience any problems in mapping this to an entity model at all. Sometimes the database design looks fine and you can easily create the entity model as well. But when you are performing some crud operations, you could encounter some issues. Luckily we have a great community here at CodeRanch to discuss and get rid of these issues in no time
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic