• 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

Resources for learning how to access multiple datasources

 
Rancher
Posts: 383
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am not sure if this is the right forum for my question, so if it should be removed to another appropriate forum feel free to let me know. I am using NetBeans 8.0 IDE, with JPA 2.1, Primefaces 4.0, running on a JBoss EAP 6.2 server (non-local JTA datasource). Currently the web app I am developing is successfully persisting to, and retrieving data from, an Oracle 11 database. But with this same web app I need to also be able to access and retrieve data from a second Oracle 11 database (I do not need to persist to it, only run queries against it to retrieve data). I have done some initial searches online but so far I have not come across any articles that seem to hit on this particular topic. Would anyone happen to know of any good material that covers something like this? If you need any more information from me please feel free to let me know. Thank you very much!

Regards,

Randy Maddocks
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using frameworks like Spring? If not, spring is very modular and you can use just spring JDBC related packages.
Of course you could also write your own code and also use some good patterns along the way (say strategy). But, spring has got elegant support for multiple databases and much more.
Consider it.
 
Randy Maddocks
Rancher
Posts: 383
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arun,

Thank you for your reply. Unfortunately we do not use the Spring framework, and it would not be my decision to introduce that framework into our model. I have decided to take your suggestion of writing my own code (using good patterns, which I completely agree with). Thanks again for your reply. Cheers.
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before you write your own code. JBOSS EAP uses hibernate as the internal JPA implementation.
In Hibernate, you configure a session factory to a database. You can declare multiple session factories to multiple databases.

A very simple example is given here.

You may also find it needed to dynamically determine the necessary session factory to run your queries or manage your object.
In that case, you can check Routing data source samples from spring.
Internally how spring does it is, it uses a key in the thread local. You can do the same. Use the key from the thread local to get the needed session factory.
 
Randy Maddocks
Rancher
Posts: 383
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent, thanks again for this information Arun!
reply
    Bookmark Topic Watch Topic
  • New Topic