我有一个正在运行的JPA应用程序,现在我想支持多租户。我喜欢使用XML而不是注释。
我从persistence.xml引用了几个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>我喜欢对所有实体使用相同的多租户配置:单表,判别器列是tenantUserId,上下文属性是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-om.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>谢谢。
发布于 2014-10-16 23:26:39
在http://www.eclipse.org/eclipselink/documentation/2.5/solutions/multitenancy002.htm中,您正确地使用了持久性单元默认值,如下所示:
<persistence-unit-metadata>
<persistence-unit-defaults>
<tenant-discriminator-column name="tenantUserId" context-property="tenant.userId"/>
</persistence-unit-defaults>
</persistence-unit-metadata>问题是您使用了错误的模式版本。2.1没有包含多租户特性,所以您需要使用2.5XDS,eclipselink_orm_2_5.xsd。这应该在eclipselink.jar中,或者像James在这里描述的那样从git中提取,http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/tree/jpa/org.eclipse.persistence.jpa/resource/org/eclipse/persistence/jpa
https://stackoverflow.com/questions/26412647
复制相似问题