Hibernate Oracle Tablespace Annotation

I comment on my DAOs and use hibernate3: hbm2ddl to generate ddls. Is there a way to annotate a tablespace?

+6
java oracle annotations hibernate
source share
1 answer

No, there is no way to do this out of the box. I have used this in the past, using the following approach - rather the involved approach:

  • Create your own @TableSpec annotation, which has a tablespace and other necessary attributes.
  • Extend org.hibernate.cfg.Configuration and override getTableMappings() to return decorated Table objects (see below).
  • Extend org.hibernate.mapping.Table and override sqlCreateString() and / or sqlAlterStrings() to add the tablespace specification (and additional settings, if any).
  • Instead of using the hbm2ddl tool (or the ant task), write your own, which will create your Configuration object, process all your class files, collect and interpret your @TableSpec annotations @TableSpec and call Configuration.generateSchemaCreationScript() or generateSchemaUpdateScript() to generate the actual DDL.

As I said, I rather participated :-) Alternatively, if ALL of your mapped tables use the same tablespace, you can extend the Oracle dialect that you use and override getTableTypeString() to return the tablespace specification. Although it's an ugly hack (since the original goal of tableTypeString is to provide the type of MySQL engine), it works and is certainly much faster and simpler than the previous approach.

+7
source share

All Articles