【发布时间】:2014-10-16 19:46:59
【问题描述】:
我正在运行一个 JPA 应用程序,现在我想支持多租户。我喜欢使用 XML 而不是注释。
我有几个从 persistence.xml 引用的 orm.xml。
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<package>mypackage</package>
<entity class="Foo" />
<entity class="Bar" />
</entity-mappings>
我喜欢对所有实体使用相同的多租户配置: 单表,discriminator 列是tenantUserId,context-property 是tenant.userId。
根据: https://wiki.eclipse.org/EclipseLink/Examples/JPA/EclipseLink-ORM.XML
<tenant-discriminator-column name="tenantUserId" context-property="tenant.userId"/>
要不要把这行放在上面?我尝试按以下方式创建 eclipselink-orm.xml
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_1.xsd"
version="2.1">
<tenant-discriminator-column name="tenantUserId" context-property="tenant.userId"/>
<persistence-unit-metadata>
<persistence-unit-defaults>
<tenant-discriminator-column name="tenantUserId" context-property="tenant.userId"/>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
根据架构,两者都是无效的。 eclipselink-orm.xml 放在哪里?
有没有办法说:所有实体都是多租户(单表)?我是否必须为所有实体一一指定它们?
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<package>mypackage</package>
<entity class="Foo" >
<multi-tenant/>
</entity>
<entity class="Bar" >
<multi-tenant/>
</entity>
</entity-mappings>
谢谢。
【问题讨论】:
标签: jpa orm eclipselink multi-tenant