Dynamically picking up a datasource (hibernate)

67 views
Skip to first unread message

Vaibhav Dhawan

unread,
Feb 9, 2017, 1:34:17 AM2/9/17
to dropwizard-user
Hi All, 

I am building up a SaaS application in which the database call goes through a set of Dropwizard services. The database structure is such that each client wants to have a separate database located on different servers altogether. However each of them will have same table structure, schema names etc.

The dropwizard services use hibernate to connect to the database. Assuming i define all these database configurations in .yml file, is there a way i can dynamically pick up the datasource on basis of the input coming in the request (i will get a client id in my request).

If not, i will have to deploy/start multiple set of dropwizard services and expect the ui layer to do the dynamic routing part. However with this approach the management of these services will be cumbersome. 

Help is appreciated. 

Thanks

Vaibhav Dhawan

unread,
Feb 10, 2017, 5:25:11 AM2/10/17
to dropwizard-user
All, 

Basically read a lot of material last night and made some progress. This is basically a multi tenant application with isolation at the database level. The entities and the DAO's will always remain same and behave in the same manner for all clients/tenants.

I was able to successfully store multiple database configurations in yml file, load them up and store in a Hash map, with key as tenant id and value as the datasource. 

The obstacle still remains is to how to pass the correct datasource or session factory to the DAO ( i am getting the tenant id in the resource and a pre request filter ). 

Thanks

Dondell Batac

unread,
Aug 8, 2021, 10:21:57 PM8/8/21
to dropwizard-user
Hi,

Have you been able to have a solution? I am also looking for a solution to the same concept.

Thanks
Reply all
Reply to author
Forward
0 new messages