Hibernate的Oracle表空间注释 [英] Hibernate Oracle Tablespace Annotation

查看:208
本文介绍了Hibernate的Oracle表空间注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的注释和的DAO Hibernate3的使用:先得用hbm2ddl生成DDL。有没有一种方法来注释表空间?

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

推荐答案

没有,有没有办法做到这一点开箱。而参与 - - 我用下面的周围了过去的做法:

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. 创建自己的注释, @TableSpec 有表和其他必要的属性。

  2. 扩展 org.hibernate.cfg.Configuration 和覆盖 getTableMappings()返回装饰对象(见下文)。

  3. 扩展 org.hibernate.mapping.Table 和覆盖 sqlCreateString()和/或 sqlAlterStrings()追加(如果有的话和附加设置)表空间规范。

  4. 而不是使用先得用hbm2ddl工具(或Ant任务)写自己,将创建配置对象,处理所有的类文件收集和跨preting您 @TableSpec 注释和引用 Configuration.generateSchemaCreationScript() generateSchemaUpdateScript()来产生实际的DDL。

  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.

正如我所说的,相当复杂:-)作为替代方案,如果所有的映射表使用相同的表空间,可以延长你使用的是Oracle的方言,并覆盖 getTableTypeString()来回报您的表空间规范。虽然这是一个丑陋的黑客(因为tableTypeString的最初目的是提供MySQL的发动机类型),它的工作原理是肯定有很多比上述方法更快,更容易。

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.

这篇关于Hibernate的Oracle表空间注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆