Closed zhtangsh closed 5 years ago
well, I saw this comment in original post, I'll close this one. Thanks.
Please create the required databases in the MySQL server you are using. This exception hints that there is no database created. You need to have databases created first.
Please read the first part of the tutorial here https://sunitkatkar.blogspot.com/2018/04/building-saas-style-multi-tenant-web.html and then read the second part here https://sunitkatkar.blogspot.com/2018/04/building-saas-style-multi-tenant-web2.html. In this second part, there is sample SQL to create required tables, etc.
These two explain the concepts and how database needs to be set up. After you have read and understood these, then read and follow https://sunitkatkar.blogspot.com/2018/05/adding-tenants-without-application.html
Also, use the code from the GitHub repo (https://github.com/sunitk/multitenancy) as it has a couple of bugs fixed and checked in.
In my project, I do not depend on Hibernate to create the schema on adding a tenant. The steps we follow is to first create the tenant schema and then make an entry in the master table. This is because the tenant database could be in a different data-center (in financial applications, some countries have regulations where database has to be physically present in the country.)
I know that the tables can get created automatically, but I have not spent time researching the way to do it for the reasons stated above.
However, there is a JDBC URL query parameter createDatabaseIfNotExistfor MySQL which will create the database and schema. Please look at this link. I have tried it in development and it did work, but decided against using it for reasons as stated above.
Hi Sunitk,
Thank you for this greate post. I clone this project and make it worked for multi tenant case. However, it seems like Hibernate only auto update schema in the first tenant datasource and I'm not sure where I went wrong. Here is spring's log
In master database, I setup two tenants as follows.
And all entities are initialized/update successfully in tenant cc, but failed in tenant dd.