1

I'm currently using Spring Data JPA, and one of the requirements is that changing the schema name in the run time. Currently, I have a fixed schema name in the application.properties like spring.jpa.properities.hibernate.default_schema=dev, but I want to change it in the run time. For example, I have several schemas named test, uat, dev, prod. and in the request header it will indicate with schema it wants to use. In this case, can anyone give me some suggestions how to solve this problem? Sincerely appreciate your help!

  • Does this answer your question? [Change database schema during runtime based on logged in user](https://stackoverflow.com/questions/39357367/change-database-schema-during-runtime-based-on-logged-in-user) – Jens Schauder Oct 20 '20 at 06:35
  • Some other questions that might be helpful: https://stackoverflow.com/questions/30195918/dynamic-schema-selection-for-spring-data-jpa-repositories-with-schema-coming-fro https://stackoverflow.com/questions/26030196/spring-jpa-dynamically-switch-the-datasource-between-schemas-in-postgresql – Jens Schauder Oct 20 '20 at 06:35
  • basically you will create key-value store of different datasource and then using runtime polymorphism you caninvoke the method on the data source you want, i suggest AGAINST it but. – silentsudo Oct 20 '20 at 12:09

0 Answers0