Spring JPA + dynamically switch the datasource between schemas in postgresql

依然范特西╮ 提交于 2021-02-08 03:05:51

问题


I have to modify design of the existing application according to following manner,

enter image description here

According to above design each project contains it's own schema and that mapping table (project_schema_table) is under main schema. All schemas are under one Postgresql database and in future users will create another new schemas (on demand) for their new projects.

Before displaying login window I have to list all existing projects and once user select his project I have to direct to that project with relevant schema. Other than main schema all other project base schemas are exactly the same.

This is a desktop application developed with latest versions of java technologies JavaFX, Spring and JPA with Postgresql database. Currently it has only one project related schema and I have to introduce main schema and all other subsequent project base schemas.

I have found similar stack overflow post but it didn't contains any solution. Whether I can accomplish this task with Spring AbstractRoutingDataSource ? or is there any other mechanism. Thanks.


回答1:


The feature you are looking for is called Multi-Tenancy and Hibernate supports this out of the box from version 4.x onwards. Please see this post on how to use this feature.



来源:https://stackoverflow.com/questions/26030196/spring-jpa-dynamically-switch-the-datasource-between-schemas-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!