I'm using postgresql with a spring/hibernate to create a multi-tenant application where every company will have its own seperate schema and tables in the database.

So when the super administrator tries to add a new company, a new schema is supposed to be added to the database as well as the new tables generated from the hibernate entities (only the entities where the schema is set to dynamic).

@Table(name = "vehicule", schema="dynamic")

The problem is that I can't figure out how to generate the database tables from the entities using a hibernate query.

I know tha it's possible to do that using :

<property name="hbm2ddl.auto" value="create"/>

But it only will work when the sessionFactory is created and not on demand.

Any help will be appreciated..

  • You'll need to think very carefully about caching too. In particular you almost certainly can't enable the 2nd level cache, since Hibernate won't know that the object with id=1 from one query isn't the same as the object with id=1 from another query. – Craig Ringer Sep 3 '15 at 13:11
  • you want to do this at runtime? i don't think that's possible. – Neil McGuigan Sep 3 '15 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.