1

我想创建基于实体和 JPA 2.0 的设计。在我们当前的架构中,我们将数据存储在 MySQL 的 2000 个分区中。每个分区都是 MyIsam 表,名称从 data_0000 到 data_1999,这只是软件解决方案。由于性能问题,我们没有使用任何特定于数据库的分区选项。这很好用,但从软件的角度来看,我们没有很好的架构。现在我们正在将所有内容迁移到 JPA,我们遇到了这样的问题。

假设当我们想向某个分区插入数据时,我们必须计算分区号(表名),即 data_(entity.object_id mod 2000)。object_id 列不为空。我们如何使用 JPA 和 EclipseLink 来设计它,如果我有 object_id=453 的实体,那么当我持久保存这个对象时,数据将存储在表 data_0453 中。我在这里http://wiki.eclipse.org/EclipseLink/Examples/JPA/Partitioning看到了许多基于addnotation 的分区示例,但其中没有一个与基于表名的分区相关。

这种情况的最佳方法是什么?

--

谢谢

4

1 回答 1

1

EclipseLink's partitioning support is for database partitioning, not table partitioning. Most databases have support for table partitioning, so it is odd you had to custom build a solution.

Can you try to encapsulate the access to the table with a view, or with stored procedures? EclipseLink allows you to override the CRUD operations with stored procedure calls, see http://wiki.eclipse.org/EclipseLink/Examples/JPA/CRUDStoredProcedures

Otherwise you could map a subclass to each table partition, but with 2000, that would probably not be a good solution. You may be able to use EclipseLink's dynamic support to avoid having the create 2000 subclasses.

You may also look into EclipseLink's multi-tenancy support, which does have some ability to choose a table based on an id.

You could also just not map the table and access it through native SQL queries.

But, I think using stored procedures is probably your best solution.

于 2013-06-12T13:56:06.473 回答