-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.

borchvm
  • 3,533
  • 16
  • 44
  • 45
  • Possible duplicate of [How to setup Hibernate to read/write to different datasources?](https://stackoverflow.com/questions/4386130/how-to-setup-hibernate-to-read-write-to-different-datasources) – XtremeBaumer Nov 11 '19 at 14:13

1 Answers1

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();
Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
  • 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 Nov 13 '19 at 14:53
  • @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. – Stanley Mungai Nov 13 '19 at 15:10