databasespringdatabase-agnostic

Database Agnostic Application


The database for one the application that I am working on is not confirmed yet by the business.

We are using Spring 3.0.5, Hibernate 3.5, JPA2 and JBoss 5 for this project

So what are the best practices here going into the build phase and test phase?

  1. Shall I build using DB2 first and worry about Oracle later (this doesn't sound right)?
  2. Or, shall I write using JPA (Hibernate) and then generate the database schema?
  3. Or something else?

PS: I've no control over the choice of the DB, what and when, as these are strategic decision made by people sitting in nice rooms getting fat cheques and big bonuses.

Thanks, Adi


Solution

  • Obviously you are loosing the access to specific features of the database if you are writing your application database agnostic. The database is, except for automatic optimizations done by JPA and Hibernate, reduced to common features. You have to set some things to automatic and trust JPA/Hibernate to do it right that you could set specifically if you knew the database (e.g. id generator strategies).

    But it seems that the specific developer features of the database are not relevant for the decision so they can't be relevant to the application. What other reasons may influence the decision (like price, money, cash, personal relations, management tools, hardware requirements, existing knowledge and personell) can only be speculated about.

    So IMHO you don't have a choice. Strictly avoid anything database specific. That includes letting the JPA/Hibernate generate the schema (your point #2). In this project setup you shouldn't tinker with the database manually.

    Well... sadly there ARE some hidden traps in JPA/Hibernate developement that make it database dependent (e.g. logarithmic functions are not mapped consistenly). So you should run all your tests against all possible databases from day one. As you write "Best guess is..." you should just grab any database available and test against it. Should be easly setup with the given stack.

    And you should try to accelerate the decision about the database used, if possible.