简体   繁体   中英

Is it possible to create multiple tables for the same jpa entity?

I have an entity Messages which is a class to log timestamp, the message and a machine_uuid

public class Messages  {

    private UUID                uuid;
    private UUID                machine;
    private long                timestamp;
    private String              message;                                        
}

If there are many machines that regularly send messages, the table can quickly become huge. Is it possible to create a separate messages table for each machine?

No. It is not possible in JPA but most Database Vendors supports 'Table Partitioning' for this case.

https://dev.mysql.com/doc/refman/8.0/en/partitioning.html

If you have one instance of DB, then you don't need to have different tables for different machine ID's. You can create INDEX for machine UUID and to make your manipulation without loosing time. It is bad practice to have different tables for different ID's.

You'll have big pain to support different tables by name, like table: messages_machine_id_1, messages_machine_id_2. Especially, when you will remove or add other machine, but, to make query using Machine ID is easy and quick.

And it is not problem, if table is huge, just add indexes and you will retrieve quickly your data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM