title: Adding Tables and Columns in Hibernate on The Fly?
body: <p>I am currently working on an application using Hibernate and we want to be able to insert columns and tables on the fly, i.e. at runtime, and continue working with the application without having to restart it. We are currently building entities, but not yet using them. We have old C code (to be migrated to Java some day) which hosts our business logic and makes calls to Java/Hibernate via JNI to get records from the database.
  After reading several threads (see below for the links) and the hibernate 3.6 reference I still have some questions:</p>
  
  <p>1.
  If I embed SchemaUpdate in my application, as mentioned here:
  <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/toolsetguide.html#toolsetguide-s1-6" rel="nofollow noreferrer">http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/toolsetguide.html#toolsetguide-s1-6</a>
  Do I then have to recreate the SessionFactory (which is an expensive operation) even if I would not use the entities (as currently the case; but in the future of course this will change)? Then, the old session will be invalid, i.e. I have to migrate the entities already in memory and maintained by the session, to the new session? Is this possible somehow?
  Does Hibernate maintain information beyond the ORM for the entities about the schemata? Wouldn't a (session, i.e. first level) cache invalidation be enough, as proposed here:
  <a href="https://stackoverflow.com/questions/4012020/changes-to-the-schema-while-hibernate-is-running">changes to the schema while hibernate is running</a></p>
  
  <p>2.
  How about altering columns?
  I guess it is still as @Bozho wrote: “Alas, hibernate can't alter columns.”?
  <a href="https://stackoverflow.com/questions/5992738/hibernate-to-update-table-schema">Hibernate to update table schema</a></p>
  
  <p>That are my questions so far, thank you for any help.</p>
  
  <p>Further references I've read:</p>
  
  <ul>
  <li>Managing Unmapped Tables with Hibernate
  <a href="http://blog.codehangover.com/536/" rel="nofollow noreferrer">http://blog.codehangover.com/536/</a></li>
  <li><a href="https://stackoverflow.com/questions/4574785/update-database-schema-with-hibernate">Update database schema with hibernate</a></li>
  <li>Very close to my question, mentions auxiliary database objects:
  <a href="https://stackoverflow.com/questions/6778991/enhance-hibernate-database-schema">Enhance Hibernate Database Schema?</a></li>
  <li>Auxiliary database objects:
  <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-database-object" rel="nofollow noreferrer">http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-database-object</a></li>
  <li><a href="http://www.liquibase.org/" rel="nofollow noreferrer">http://www.liquibase.org/</a></li>
  <li><a href="http://www.alittlemadness.com/2006/08/28/incremental-schema-upgrades-using-hibernate/" rel="nofollow noreferrer">http://www.alittlemadness.com/2006/08/28/incremental-schema-upgrades-using-hibernate/</a></li>
  </ul>