• 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

Framework capabilities with multiple databases

 
Ranch Hand
Posts: 333
1
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

Dave
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Bartender
Posts: 1152
20
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic