Forums Register Login

Resources for learning how to access multiple datasources

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Excellent, thanks again for this information Arun!
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 692 times.
Similar Threads
Issue with understanding EJB functionality as it relates to Primefaces/JPA/JTA
Deciding on what method to use to avoid LazyInitializationExceptions
Multiple DB access using multiple persistent units in same persistence.xml file
Primefaces selectOneMenu not populated with data from database (using JPA)
JBOSS 4.3.0 EAP Clustering with Apache HTTP Server 2.2.11
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:27:44.