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:
- Create your own annotation,
@TableSpec
that has tablespace and other necessary attributes. - Extend
org.hibernate.cfg.Configuration
and overridegetTableMappings()
to return decoratedTable
objects (see below). - Extend
org.hibernate.mapping.Table
and overridesqlCreateString()
and / orsqlAlterStrings()
to append tablespace specification (and additional settings if any). - 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 invokeConfiguration.generateSchemaCreationScript()
orgenerateSchemaUpdateScript()
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
2009-08-13 21:17:21