Spring JPA +在Postgresql中的模式之间动态切换数据源 [英] Spring JPA + dynamically switch the datasource between schemas in postgresql

查看:387
本文介绍了Spring JPA +在Postgresql中的模式之间动态切换数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须按照以下方式修改现有应用程序的设计,

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

根据上述设计,每个项目都包含其自己的架构,并且映射表(project_schema_table)位于主架构下.所有模式都在一个Postgresql数据库下,将来用户将为他们的新项目创建另一个新模式(按需).

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.

这是一个桌面应用程序,使用最新版本的Java技术JavaFX,Spring和JPA与Postgresql数据库一起开发.当前它只有一个与项目相关的架构,我必须介绍主架构以及所有其他后续的项目基础架构.

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.

我发现了类似的堆栈溢出帖子,但其中没有任何解决方案.我是否可以使用Spring

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.

推荐答案

您正在寻找的功能称为Multi-Tenancy,而Hibernate从4.x版本开始就支持此功能.请参阅此帖子关于如何使用此功能.

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.

这篇关于Spring JPA +在Postgresql中的模式之间动态切换数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆