Go Premium for a chance to win a PS4. Enter to Win


Accessing different database schemas using JNDI with Spring and Hibernate

Posted on 2009-05-12
Medium Priority
Last Modified: 2015-01-05

We are using Struts2+Spring+Hibernate+JNDI in our project. In our database we have tables in different schemas. At runtime, the DB schema must be selected dynamically depending on the user selection. How can I make Spring+JNDI pick up the right DB schema or datasource at runtime?
Question by:cuttieveenz
  • 3
LVL 11

Expert Comment

ID: 24382794
You can have a properties file that has mapping for schema - datasource name. This mapping can be picked up statically and your connection class can use the correspoding class to return the relevant connection.
LVL 11

Expert Comment

ID: 24382816
Should be

your connection class can use the correspoding JNDI datasource to return the relevant connection from pool.

Author Comment

ID: 24401733
I have read something about the AbstractRoutingDataSource class. How is this used?
LVL 11

Accepted Solution

anilallewar earned 2000 total points
ID: 24448130
The AbstractRoutingDataSource  is the concrete implementation of the methodology that I described above that is available in the Spring framework. You can find more details & example with Spring on the below sites.


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question