I have a JPA application running, and now I want to support multi-tenancy. I like to use XML instead of annotations.
I have a couple of orm.xml referenced from persistence.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>
I like to use the same multi-tenancy configuration for all entities: single-table, discriminator column is tenantUserId, context-property is tenant.userId.
According to: https://wiki.eclipse.org/EclipseLink/Examples/JPA/EclipseLink-ORM.XML
<tenant-discriminator-column name="tenantUserId" context-property="tenant.userId"/>
Whether to put the line above? I tried to create eclipselink-orm.xml as following
<?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>
Both are invalid according to the schema. Where to put eclipselink-orm.xml?
Is there a way to say that: all entities are multi-tenant(single table)? Do I have to specify them for all entities one by one?
<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>
Thanks.