站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate reference 3.2.0 ga 正式版中文参考手册

5.7. 辅助数据库对象(Auxiliary Database Objects) - Hibernate reference 3.2.0 ga 正式版中文参考手册

5.7. 辅助数据库对象(Auxiliary Database Objects)

Allows CREATE and DROP of arbitrary database objects, in conjunction with Hibernate's schema evolution tools, to provide the ability to fully define a user schema within the Hibernate mapping files. Although designed specifically for creating and dropping things like triggers or stored procedures, really any SQL command that can be run via a java.sql.Statement.execute() method is valid here (ALTERs, INSERTS, etc). There are essentially two modes for defining auxiliary database objects... 帮助CREATE和DROP任意数据库对象,与Hibernate的schema交互工具组合起来,可以提供在Hibernate映射文件中完全定义用户schema的能力。虽然这是为创建和销毁trigger(触发器)或stored procedure(存储过程)等特别设计的,实际上任何可以在java.sql.Statement.execute()方法中执行的SQL命令都可以在此使用(比如ALTER, INSERT,等等)。本质上有两种模式来定义辅助数据库对象...

第一种模式是在映射文件中显式声明CREATE和DROP命令:

<hibernate-mapping>
    ...
    <database-object>
        <create>CREATE TRIGGER my_trigger ...</create>
        <drop>DROP TRIGGER my_trigger</drop>
    </database-object>
</hibernate-mapping>

第二种模式是提供一个类,这个类知道如何组织CREATE和DROP命令。这个特别类必须实现org.hibernate.mapping.AuxiliaryDatabaseObject接口。

<hibernate-mapping>
    ...
    <database-object>
        <definition class="MyTriggerDefinition"/>
    </database-object>
</hibernate-mapping>

还有,这些数据库对象可以特别指定为仅在特定的方言中才使用。

<hibernate-mapping>
    ...
    <database-object>
        <definition class="MyTriggerDefinition"/>
        <dialect-scope name="org.hibernate.dialect.Oracle9Dialect"/>
        <dialect-scope name="org.hibernate.dialect.OracleDialect"/>
    </database-object>
</hibernate-mapping>