`

hibernate工具箱指南

阅读更多

可以通过一系列Eclipse插件、命令行工具和Ant任务来进行与Hibernate关联的转换。

除了Ant任务外,当前的Hibernate Tools也包含了Eclipse IDE的插件,用于与现存数据库的逆向工程。

  • Mapping Editor: Hibernate XML映射文件的编辑器,支持自动完成和语法高亮。它也支持对类名和属性/字段名的语义自动完成,比通常的XML编辑器方便得多。

  • Console: Console是Eclipse的一个新视图。除了对你的console配置的树状概览,你还可以获得对你持久化类及其关联的交互式视图。Console允许你对数据库执行HQL查询,并直接在Eclipse中浏览结果。

  • Development Wizards: 在Hibernate Eclipse tools中还提供了几个向导;你可以用向导快速生成Hibernate 配置文件(cfg.xml),你甚至还可以同现存的数据库schema中反向工程出POJO源代码与Hibernate 映射文件。反向工程支持可定制的模版。

  • Ant Tasks:

要得到更多信息,请查阅 Hibernate Tools 包及其文档。

同时,Hibernate主发行包还附带了一个集成的工具(它甚至可以在Hibernate“内部”快速运行)SchemaExport ,也就是 hbm2ddl

可以从你的映射文件使用一个Hibernate工具生成DDL。 生成的schema包含有对实体和集合类表的完整性引用约束(主键和外键)。涉及到的标示符生成器所需的表和sequence也会同时生成。

在使用这个工具的时候,你必须 通过hibernate.dialet属性指定一个SQL方言(Dialet),因为DDL是与供应商高度相关的。

首先,要定制你的映射文件,来改善生成的schema。

很多Hibernate映射元素定义了一个可选的length属性。你可以通过这个属性设置字段的长度。 (如果是Or, for numeric/decimal data types, the precision.)

有些tag接受not-null属性(用来在表字段上生成NOT NULL约束)和unique属性(用来在表字段上生成UNIQUE约束)。

有些tag接受index属性,用来指定字段的index名字。unique-key属性可以对成组的字段指定一个组合键约束(unit key constraint)。目前,unique-key属性指定的值并不会被当作这个约束的名字,它们只是在用来在映射文件内部用作区分的。

示例:

<property name="foo" type="string" length="64" not-null="true"/>
<many-to-one name="bar" foreign-key="fk_foo_bar" not-null="true"/>
<element column="serial_number" type="long" not-null="true" unique="true"/>

另外,这些元素还接受<column>子元素。在定义跨越多字段的类型时特别有用。

<property name="foo" type="string">
<column name="foo" length="64" not-null="true" sql-type="text"/>
</property>
<property name="bar" type="my.customtypes.MultiColumnType"/>
<column name="fee" not-null="true" index="bar_idx"/>
<column name="fi" not-null="true" index="bar_idx"/>
<column name="fo" not-null="true" index="bar_idx"/>
</property>

sql-type属性允许用户覆盖默认的Hibernate类型到SQL数据类型的映射。

check属性允许用户指定一个约束检查。

<property name="foo" type="integer">
<column name="foo" check="foo > 10"/>
</property>
<class name="Foo" table="foos" check="bar < 100.0">
...
<property name="bar" type="float"/>
</class>
评论

相关推荐

    Hibernate 3.6.0.Final Reference PDF 手册

    第 22 章 工具箱指南 第 23 章 Additional modules 第 24 章 示例:父子关系(Parent/Child) 第 25 章 示例:Weblog 应用程序 第 26 章 示例:复杂映射实例 第 27 章 最佳实践(Best Practices)...

    hibernate中文参考文档

    1、在Tomcat中快速上手 2、体系结构 3、SessionFactory配置 4、持久化类 5、O/R Mapping基础 6、集合类映射 ...15、工具箱指南 16、示例:父子关系 17、示例:Weblog应用程序 18、示例:不同的映射 19、最佳实践

    Hibernate+中文文档

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. ...

    Hibernate框架参考文档

    本压缩软件集中了大量的Hibernate资料,目录如下: ...20. 工具箱指南; 21. 示例:父子关系(Parent Child Relationships); 22. 示例:Weblog 应用程序; 23. 示例:复杂映射实例; 24. 最佳实践(Best Practices);

    hibernate3.2中文文档(chm格式)

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. ...

    HibernateAPI中文版.chm

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. ...

    hibernate 教程

    工具箱指南 15.1. Schema 生成器(Schema Generation) 15.1.1. 对schema定制化(Customizing the schema) 15.1.2. 运行该工具 15.1.3. 属性(Properties) 15.1.4. 使用Ant(Using Ant) 15.1.5. 对...

    Hibernate中文详细学习文档

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. ...

    Hibernate 中文 html 帮助文档

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. 对...

    Hibernate教程

    21. 工具箱指南 21.1. Schema自动生成(Automatic schema generation) 21.1.1. 对schema定制化(Customizing the schema) 21.1.2. 运行该工具 21.1.3. 属性(Properties) 21.1.4. 使用Ant(Using Ant) 21.1.5. ...

    hibernate 体系结构与配置 参考文档(html)

    1. Hibernate入门 1.1. 前言 1.2. 第一部分 - 第一个Hibernate应用程序 1.2.1. 第一个class 1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第...

    最全Hibernate 参考文档

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. 对...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. ...

    hibernate

    工具箱指南 15.1. Schema 生成器(Schema Generation) 15.1.1. 对schema定制化(Customizing the schema) 15.1.2. 运行该工具 15.1.3. 属性(Properties) 15.1.4. 使用Ant(Using Ant) 15.1.5. 对...

    hibernate3.04中文文档.chm

    21. 工具箱指南 21.1. Schema自动生成(Automatic schema generation) 21.1.1. 对schema定制化(Customizing the schema) 21.1.2. 运行该工具 21.1.3. 属性(Properties) 21.1.4. 使用Ant(Using Ant) 21.1.5. ...

    hibernate 框架详解

    2. Hibernate入门 2.1. 前言 2.2. 第一部分 - 第一个Hibernate程序 2.2.1. 第一个class 2.2.2. 映射文件 2.2.3. Hibernate配置 2.2.4. 用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二...

    Hibernate3+中文参考文档

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. 对...

    Hibernate参考文档

    20. 工具箱指南 20.1. Schema自动生成(Automatic schema generation) 20.1.1. 对schema定制化(Customizing the schema) 20.1.2. 运行该工具 20.1.3. 属性(Properties) 20.1.4. 使用Ant(Using Ant) 20.1.5. 对...

    NHibernate参考文档 2.0.0 chm

    17. 工具箱指南 17.1. 数据库结构生成(schema generation) 17.1.1. 对schema定制化(Customizing the schema) 17.1.2. 运行该工具 17.1.3. 配置属性(Properties) 17.1.4. 使用NAnt 17.2. 代码生成 17.2.1. 配置文件...

    NHibernate中文帮组文档(2008.11月更新)

    17. 工具箱指南 17.1. 数据库结构生成(schema generation) 17.1.1. 对schema定制化(Customizing the schema) 17.1.2. 运行该工具 17.1.3. 配置属性(Properties) 17.1.4. 使用NAnt 17.2. 代码生成 17.2.1. 配置文件...

Global site tag (gtag.js) - Google Analytics