Solved

Accessing different database schemas using JNDI with Spring and Hibernate

Posted on 2009-05-12
5
1,155 Views
Last Modified: 2015-01-05
Hi,

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?
0
Comment
Question by:cuttieveenz
  • 3
5 Comments
 
LVL 11

Expert Comment

by:anilallewar
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.
0
 
LVL 11

Expert Comment

by:anilallewar
ID: 24382816
Should be

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

Author Comment

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

Accepted Solution

by:
anilallewar earned 500 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.

http://blog.springsource.com/2007/01/23/dynamic-datasource-routing/
http://www.jdocs.com/spring/2.5.2/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.html
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to setup 18 92
Receive file in Servlet 1 39
array11 challenge 16 59
countHi2 challenge 7 52
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now