Kadzhaev Marat
Kadzhaev Marat

Reputation: 1317

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?

Upvotes: 4

Views: 310

Answers (1)

Kadzhaev Marat
Kadzhaev Marat

Reputation: 1317

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

Upvotes: 2

Related Questions