Clone a Table's definition with Hibernate (hbm2ddl)

后端 未结 1 1248
有刺的猬
有刺的猬 2021-01-07 01:21

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

相关标签:
1条回答
  • 2021-01-07 02:23

    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 :-)

    0 讨论(0)
提交回复
热议问题