views:

264

answers:

1

I'm annotating my DAOs and using hibernate3:hbm2ddl to generate the ddls. Is there a way to annotate the tablespace?

+2  A: 

No, there is no way to do it out of the box. I've got around it in the past using the following - rather involved - approach:

  1. Create your own annotation, @TableSpec that has tablespace and other necessary attributes.
  2. Extend org.hibernate.cfg.Configuration and override getTableMappings() to return decorated Table objects (see below).
  3. Extend org.hibernate.mapping.Table and override sqlCreateString() and / or sqlAlterStrings() to append tablespace specification (and additional settings if any).
  4. Instead of using hbm2ddl tool (or ant task) write your own that will create your Configuration object, process all your class files collecting and interpreting your @TableSpec annotations and invoke Configuration.generateSchemaCreationScript() or generateSchemaUpdateScript() to generate actual DDL.

As I said, rather involved :-) As an alternative, if ALL your mapped tables use the same tablespace, you can extend Oracle dialect you're using and override getTableTypeString() to return your tablespace spec. While this is an ugly hack (because tableTypeString's original purpose is to provide MySQL engine type), it works and is certainly a lot faster and easier than above approach.

ChssPly76