Because a large amount of data is accumulating in the log table, I want to dynamically create and save an additional table in log_yyyymm(log_202402, ...) format.
In jpa, I have no idea how to "dynamically" create a table at runtime and select with a dynamically created table name.
I'm not talking about the auto_ddl option. This does not mean that the table is automatically created when springboot is loaded.
It may be that dynamic creation is supported in that format. plz help me..
environment: java, spring boot, jpa, mysql
You can use DDL from JPA to create the table. Native query for example, you first compute the name of the table and pass it as an argument.
But you have to be more specific on what your use case is: you can create the table from JPA but what do you want to do with it ? move data from the original table or start writing in it after a certain period ?
For the first case you can create a trigger or async method that moves data from time to time or other criteria.
For the second use case, in case you want to do inserts in it, you will not be able to use Entities because you can not dynamically change the @Entity(name='table_name')