如何在eclipselink中访问多个租户? [英] How to access multiple tenants in eclipselink?

查看:131
本文介绍了如何在eclipselink中访问多个租户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

eclipselink(或Hibernate)中的租户是将数据域彼此分开的一个很好的概念。我正在使用eclipselink和单表策略。

Tenants in eclipselink (or Hibernate) are a great concept to separate data domains from each other. I am using eclipselink with single-table strategy.

有时需要从多个租户访问数据(例如,出于管理目的)。有没有一个很好的方法来实现这一目标? (我不想通过所有租户来收集数据......)

Sometimes it is necessary to access data from more than just one tenant (e.g. for admin purposes). Is there a good way to achieve that? (I do not want to run through all tenants to collect the data...)

示例:

@Entity
@Multitenant
@TenantDiscriminatorColumn(name = "TENANT", contextProperty = "tenant.id")
public class TenantEntity {
    ...

我可以使用参数化实体管理器访问特定租户中的对象:

I can access the objects in a specific tenant with a parameterized entity manager:

private static EntityManager newEntityManager(String tenant) {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("tenant.id", tenant);
    return emf.createEntityManager(map);
}

有没有方便的方法来查询所有租户? (或者是仅在单个租户中定义的持久对象的标识?)

Is there any convenient way to query over all tenants? (Or is the identity of a persisted object only defined in a single tenant?)

推荐答案

EclipseLink有一个允许的开放功能请求允许管理服务器访问多租户数据的更好方法: https://错误.eclipse.org / bugs / show_bug.cgi?id = 355458 - 如果它对您很重要,请投票赞成。

EclipseLink has an open feature request to allow a better way of allowing an admin server to access multi tenant data: https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458 - vote for it if it is important to you.

解决方法是为管理控制台创建一个单独的持久性单元。解决此问题的一种方法是将多租户元数据移动到EclipseLink orm.xml文件,并在租户persitence单元中使用它,而管理持久性单元只使用实体类。您可能希望实体中的字段可以映射到管理控制台可以使用和查询的租户列,但是对于租户特定的持久性单元而言是只读的或不可访问的。

The way around it would be to create a separate persistence unit for your admin console. One way to go about this would be to move the multitenant metadata to an EclipseLink orm.xml file, and use it in your tenant persitence units, while the admin persistence unit just use the entity classes. You might want a field in the entities that can be mapped to the tenant column that the admin console could use and query against, but be read-only or inaccessible to the tenant specific persistence units.

这篇关于如何在eclipselink中访问多个租户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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