In my hibernate application there is annotation driven object: AuditEvent. Its very simple and has no foreign key relationships. I archive old entries in this tab
It's doable but rather messy and, most likely, not worth it in this case.
You'll need to dynamically alter Hibernate's Configuration object before SessionFactory is built. I you're using Spring, this can be done by overriding postProcessAnnotationConfiguration()
method of AnnotationSessionFactoryBean
; otherwise you'll just need to do it using your Configuration
object prior to invoking buildSessionFactory()
on it.
You can get access to class / table mappings via configuration.getMappings()
. You will then need to find your table mapping via getTable()
, create a copy with new name via addTable()
and replicate all columns / keys via Table API.
You can then generate the DDL script via generateSchemaCreationScript()
or generateSchemaUpdateScript()
methods of Configuration
object.
As I said, probably not worth it in this case :-)