Clone a Table's definition with Hibernate (hbm2ddl)?

It's doable but rather messy and, most likely, not worth it in this case You'll need to dynamically alter bernate'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 :-).

It's doable but rather messy and, most likely, not worth it in this case. You'll need to dynamically alter bernate'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 :-).

I will try this and see if it works! Even for 2 tables, I think it is worth it -- manual steps in a cross-platform build process just drag things down and cause unexpected problems. – Justin Aug 6 '09 at 21:36 Good luck with your implementation.

The above approach works for me, though I'm using it for a different purpose (runtime entity mapping manipulation). I've got to say, though, that I'm quite annoyed by bernate reordering columns in DDL script - I want to maintain the same order as in source code annotations. Have you somehow resolved that or is that not an issue for you?

– ChssPly76 Aug 6 '09 at 22:00 Our dev process is: annotated POJO -> DDL. We always go through hibernate property names, so we don't care about column positions. If hibernate is reordering randomly, that means its probably using a HashSet/Map somewhere internally.

Find the code switch it to a TreeSet/Map and you might get consistent ordering? – Justin Aug 6 '09 at 22:22 * that would give you sorted and consistent order, but not what you want. You need to apply a sort at the end process which scans the annotations and reorders the internal hibernate structure based on the class annotation.

– Justin Aug 6 '09 at 22:27 Yes, I do that for regular attributes, and it's a huge pain :-) It's next to impossible to do that for associations, though (without rewriting a significant part of bernate metadata objects) so they always go last in the table. I've made my peace with that :-) but when I saw you were generating DDL from POJO annotations I figured I'd check if you have faced and perhaps resolved that issue. – ChssPly76 Aug 6 '09 at 22:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions