Spring JPA +在Postgresql中的模式之间动态切换数据源

编程入门 行业动态 更新时间:2024-10-27 13:27:30
本文介绍了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 AbstractRoutingDataSource 吗?或是否有任何其他机制.谢谢.

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中的模式之间动态切换数据源

本文发布于:2023-10-29 03:02:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   模式   动态   Spring   JPA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!