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:
1. If I embed SchemaUpdate in my application, as mentioned here: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/toolsetguide.html#toolsetguide-s1-6 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: changes to the schema while hibernate is running
2. How about altering columns? I guess it is still as @Bozho wrote: “Alas, hibernate can't alter columns.”? Hibernate to update table schema
That are my questions so far, thank you for any help.
Further references I've read:
- Managing Unmapped Tables with Hibernate http://blog.codehangover.com/536/
- Update database schema with hibernate
- Very close to my question, mentions auxiliary database objects: Enhance Hibernate Database Schema?
- Auxiliary database objects: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-database-object
- http://www.liquibase.org/
- http://www.alittlemadness.com/2006/08/28/incremental-schema-upgrades-using-hibernate/