我正在使用java,jpa(eclipselink),mysql開發具有「共享數據庫/獨立架構」方法的多租戶Web應用程序。我的持久性文件看起來像:如何使用eclipselink在基於多架構的多租戶Web應用程序中添加缺失的列
<persistence-unit name="GroupBuilderPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/?"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<--- Here goes other properties definition -->
</persistence-unit>
現在,這裏是我的EntityMangerFactory和EntityManager的:
emfForTenant = Persistence.createEntityManagerFactory("GroupBuilderPU");
EntityManager em = emfForTenant.createEntityManager();
em.setProperty("eclipselink.tenant-id", schemaNameAsTenantId);
其工作正常,直到我在任何實體添加任何新的持久性列。
像我一個實體UserAccount在那裏我已經添加了一個新列「字符串rentalinfo」:
@Entity
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
public class UserAccount implements Serializable {
...
private String rentalinfo;//Newly added column
...
}
現在,經過這下面一行是給錯誤:
em.createQuery("SELECT ua FROM UserAccount ua").getResultList();
的錯誤是:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'RENTALINFO' in 'field list'
那麼在此應用程序中添加新列(擴展表)的解決方案是什麼?蟑螂?
Yeap,我知道ddl世代不支持MultitenantType.Table_PER_TENANT。順便說一句,解決方案是使用任何數據庫遷移工具,如flyway,liquibase等我使用flyway的解決方案:) –
@FarhanNazmul啊,我假定你正在尋找一個解決方案,涉及EclipseLink擴展你的桌子..那麼是的,解決辦法就是自己擴展桌子或者使用工具......很高興你能解決問題。 –