How to add tables at run time using Hibernate


I have a scenario that the tables are TestRunNumber specific. So while creating Model(POJO classes), I have used hibernate naming strategy to change the table name according to TestRunNumber.

Whenever we click on any testrun, I want that the table of that testrun should get loaded in Session Factory at run time. Currently I had to keep HashMap which contains SessionFactory according to the testrun number, but this design is not good as there will be may SessionFactory objects.

Suggest me a solution for the same.


The Hibernate metamodel is built during bootstrap and cannot be changed afterwards. However, instead of keeping one SessionFactory for each test run, you could try to use multitenancy instead of renaming tables.

You could use either create a new catalog or schema for each test run and use of the following two multitenancy strategies: