1

I am building a multi-tenant application, where the tenant database configuration are stored in Redis. Based on the request, I will query the Redis to get the database and schema configured for that tenant, this application is built on spring boot.

I took a look at spring boot's JPA sample, and did some more google to find a suitable solution for this, unfortunately, I couldn't find one.

Is this really possible to use JPA sample provided here ? https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-jpa

Please suggest me any other best possible way to tackle this problem

Thanks

1 Answer 1

1

Spring Data JPA uses JPA annotations to define domain model. These JPA entities define schema for your database. Obviously you can't change these entities, nor DB schema on runtime.

So no, updating schema on runtime is not possible with Spring Boot + Spring Data JPA combo.

Database connection (e.g. DB URL, username password) could be more flexible. You would need to create DataSource beans programmatically and somehow programatically define which data source to use for each query per tenant. But this wasn't requirement of Spring nor JPA ecosystem, therefore you may face lot of issues.

I was working on such system before, but we were using plain SQL queries via JDBC and were creating DB connection programatically to achieve schema changes on runtime.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.