Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Framework capabilities with multiple databases

Ranch Hand
Posts: 242
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a small web application at the moment which is in effect a servlet. It supports connecting to 3 different types of database (Oracle, mySQL and MS SQL) as all the SQL statements for each transaction are stored in a file for the chosen database type. In effect a single instance of the application can have user 1 connected to an oracle version of the database while at the same time user 2 is using mySQL and user 3 MS SQL. That never happens in reality but it does mean I only have 1 version of my application which can without change support any of those database platforms. An XML file holds the database connection and type settings and the user selects which database he/she wants to connect to during the logon process.

So - if I wanted to embrace modern frameworks like Spring for example - would it be possible provide that kind of flexibility.

From most of my googling it seems that frameworks assume your going to pick a single type of database and use hibernate to generate the schema code etc.

Any feedback / experience which could lead me in the right direction would be most helpful.

Many thanks

Saloon Keeper
Posts: 5573
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate (and other ORM solutions like JPA) can connect to multiple persistence providers from within the same code. They don't care about what kind of DB those providers represent, as long as the DBs are supported by the ORM mechanism (which all the major DBs, those you mentioned and the rest, are).
Posts: 1025
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have a look at Spring Data, and maybe specifically Spring Data JPA.
I've not really had time too look at this, and it was only briefly covered in a pivotal course I did, but it looks good.  

You seem to be creating repositories interfaces, and letting spring handle all the normal CRUD code; like they say in the docs:

"The goal of Spring Data repository abstraction is to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores."

As always the Spring Docs are pretty good; Spring Data JPA Docs

Sadly, I've not had time to look at this in any great detail.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!