-1

I have been trying to find a solution but with no luck.

I have an Java application (Tapestry) and Hibernate to connect to database. Now there are 3 companies that want to use the same instance of application but different database.

What I have to do is depending on company that accesses the app use different database.

1

1 Answer 1

0

You can load different config Files in Hibernate Depending on the company. Just have the Hibernate Config files in Different location per company and configure session from different databases using:

File f = new File("C:\\company_name\\hibernate.cfg.xml");

SessionFactory sessionFactory = new Configuration().configure(f).buildSessionFactory();
Sign up to request clarification or add additional context in comments.

2 Comments

i tried when user logs in get companyParameter and depending on that load companyParameter+hibernate.cfg file but somehow somewhere on startup still it searches for the default hibernate.cfg --------------- Configuration cfg = new Configuration().configure(companyParameter+"hibernate.cfg.xml");
@user3175322 You are passing a String into configure(string) method. The expectation is that the String is in classpath. Please pass a File parameter as in the example I have given above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.