Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice managing multiple dynamically created databases through Spring and Hibernate?

Let say that for each customer you have to dynamically create a database when customer subscribes to services, all databases are based on same schema.

As customers are authenticated (one master database managing all customer details), their unique username is used to access the corresponding database and retrieve needed information.

Question 1: Can the above be considered a good approach to this kind of problem or is there a better solution?

Question 2: In case there is no better solution, how can this be implemented using Spring & Hibernate?

Edit: What I need to know, is how to implement datasource creation upon customer subscription without editing the Spring configuration file. It needs to be automated.

like image 866
a.s.t.r.o Avatar asked Jan 26 '26 20:01

a.s.t.r.o


1 Answers

Question 1: There are various options. This article talks about these options with pros and cons of each option.

Question 2:

  1. Spring supports dynamic data source routing. May be you should start from there.
  2. You can also create the data sources dynamically provided you let Spring manage the data sources for you. All you have to do is register a bean of type com.mchange.v2.c3p0.ComboPooledDataSource or org.apache.commons.dbcp.BasicDataSource in the running Spring app ctx. Read the article Altering your applicationContext at runtime on how do this.

Related

  1. Configure spring datasource for hibernate and @Transactional
  2. DBCP
  3. c3p0
like image 125
Aravind Yarram Avatar answered Jan 29 '26 10:01

Aravind Yarram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!