Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Oracle Tablespace Annotation

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

like image 562
l15a Avatar asked Aug 13 '09 20:08

l15a


1 Answers

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.

like image 65
ChssPly76 Avatar answered Oct 20 '22 04:10

ChssPly76