英文:
Multi-tenency with Spring JPA
问题
我们正在使用Spring Boot和JPA(EclipseLink)构建一个多租户应用程序。我们已经完成了以下步骤。
- 定义了AbstractRoutingDataSource。
- 为每个租户定义了新的LocalContainerEntityManagerFactoryBean Bean。
现在在我们的代码中,有两种类型的情况。
- @PersistenceContext注解
这两种情况都没有限定符。问题是,我们无法添加限定符,例如持久化单元名称,因为我的租户将是动态的。
是否有任何方法可以解决这个问题。也就是说,在运行时它将在不在PersistenceContext中硬编码unitname的情况下,附加正确的实体管理器。
非常感谢。
英文:
We are building a multi-tenant application using spring boot, JPA (Eclipselink). We have done below steps.
- Defined AbstractRoutingDatasource
- Defined new Bean of LocalContainerEntityManagerFactoryBean for each tenant
Now in our code, we have two types of flavour.
- @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
专注分享java语言的经验与见解,让所有开发者获益!
评论