Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring multi tenancy

I have two databases: Oracle and PostgreSQL where I have multiple schemas - one per each customer. I need to have an opportunity to route datasources by web request. I tried to use Spring's AbstractRoutingDatasource but it works only with single dialect. Are there any other solutions for this task?

like image 301
Kadzhaev Marat Avatar asked Oct 17 '25 16:10

Kadzhaev Marat


1 Answers

I found a solution. You can explicitly tell Hibernate which dialect to choose using hibernate.dialect property. So you can implement your own dialect extends org.hibernate.dialect.Dialect class, override all public methods and delegate calls to specific dialects. The good thing is Hibernate calls this (Dialect's) methods before performing any database requests. In my specific case I've implemented a custom dialect with map of dialects I need for my project and now I can use the same repositories and freely choose Postgresql, Oracle or MySQL depending on logged in user

like image 67
Kadzhaev Marat Avatar answered Oct 20 '25 05:10

Kadzhaev Marat



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!