我目前正在使用 Hibernate 和 MultiTenancy 选项(MySQL 中每个租户的架构......因此每个租户的 DB)。我们有一个连接提供者和租户标识符的实现,可以为我们正确地切换数据库模式。伟大的。
现在,我们要开始探索在我们的应用程序中使用二级缓存。通过文档,不清楚这是否正常工作。
对于给定的租户数据库,将有具有给定 DB id... 1,2,3 等的行作为主键。当我有两个租户 DB 时,这些实体是否分开存储? Hibernate 会正确地为每个租户创建缓存(有效地)吗?
最佳答案
在第 19.4.3 节“缓存”中,即某些早期版本中的第 16.3.3 节,Hibernate 5.2 文档说:
Multitenancy support in Hibernate works seamlessly with the Hibernate second level cache. The key used to cache data encodes the tenant identifier.
上面的引用似乎是确定的,但在同一部分中,信息说明添加了:
Currently, schema export will not really work with multitenancy. That may not change. The JPA expert group is in the process of defining multitenancy support for an upcoming version of the specification.
该说明直接解决了模式导出问题,但它对二级缓存和 Multi-Tenancy 的影响尚不清楚。似乎表明 native Hibernate 完全支持 Multi-Tenancy ,但它的 JPA 实现可能不支持,尽管我可能会过度阅读该部分。
关于java - 使用 Hibernate 二级缓存和 Multi-Tenancy ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41733699/