多租户与Spring JPA

huangapple 未分类评论65阅读模式
英文:

Multi-tenency with Spring JPA

问题

我们正在使用Spring Boot和JPA(EclipseLink)构建一个多租户应用程序。我们已经完成了以下步骤。

  1. 定义了AbstractRoutingDataSource。
  2. 为每个租户定义了新的LocalContainerEntityManagerFactoryBean Bean。

现在在我们的代码中,有两种类型的情况。

  1. @PersistenceContext注解

这两种情况都没有限定符。问题是,我们无法添加限定符,例如持久化单元名称,因为我的租户将是动态的。

是否有任何方法可以解决这个问题。也就是说,在运行时它将在不在PersistenceContext中硬编码unitname的情况下,附加正确的实体管理器。

非常感谢。

英文:

We are building a multi-tenant application using spring boot, JPA (Eclipselink). We have done below steps.

  1. Defined AbstractRoutingDatasource
  2. Defined new Bean of LocalContainerEntityManagerFactoryBean for each tenant

Now in our code, we have two types of flavour.

  1. @Persistencecontext

Both do not have a qualifier. Problem is we can not add qualifier example persistence unit name as my tenants will be dynamic.

Is there any way we can solve it. Means on runtime, it will attach the right entity manager with out hardcoding unitname in the persitenceContext

Thanks a lot

huangapple
  • 本文由 发表于 2020年7月28日 22:45:40
  • 转载请务必保留本文链接:https://java.coder-hub.com/63136830.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定