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 table by moving them to another table OldAuditEvent, which is a clone of the AuditEvent table.
Right now we generate the DDL for the entire application using hbm2ddl (on our annotated datamodel) and manually copy/paste the AuditEvent table and change its name to create OldAuditEvent.
I want to automate the build process, is there any way to tell hbb2ddl: "hey take this entity, change the table name to X and regenerate it's DDL"?
Update: I was able to get this working by the approach you outlined. The only trouble was getting at the AnnotationSessionFactoryBean since it is a factory bean and spring will only give you the output of its factory. I created ConfigExposingAnnotationSessionFactoryBean (extending AnnotationSessionFactoryBean) to expose the bean factory through a static -- sort of a hack but all I want to do is run a build time task.
Configuration cfg = ConfigExposingAnnotationSessionFactoryBean.s_instance.getConfiguration();
PersistentClass pClass = cfg.getClassMapping("com.myco.LoginAttempt");
pClass.getTable().setName("ArchiveLoginAttempt");
Dialect dialect = Dialect.getDialect(ConfigExposingAnnotationSessionFactoryBean.s_instance.getHibernateProperties());
// only output create tables, not indexes or FK
for (String s : cfg.generateSchemaCreationScript( dialect )) {
if (s.contains("create table") && s.contains("Archive")) {
m_outstream.print(s);
m_outstream.println(";");
}
}