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

Create a post

All things programming and coding related. Subcommunity of Technology.


This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

  • 1 user online
  • 2 users / day
  • 2 users / week
  • 8 users / month
  • 98 users / 6 months
  • 1 subscriber
  • 302 Posts
  • 2.15K Comments
  • Modlog