Spring JPA Entity table name from request
Spring JPA Entity table name from request
I have multiple tables with the same schema. The only difference is the table name. Table names are in the format table_name_<tenant_id>
, for example, table_name_1
, table_name_24
, table_name_15
etc.,
I want to use a single Entity and JPA repository to perform operations on this table. I get the tenant_id from the Request. I want to execute queries on the corresponding tables.
How do I dynamically set the table name to be used for querying?
We have only 5 such tables since the data for each tenant is very high
Not adding a MWE since I couldn't find any place to start trying approaches.
Edit: Replace user_id
with tenant_id
and add number of tables present
0
comments