中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Java > Struts/Hibernate
hbm2java和hbm2ddl工具的使用
作者:未知 时间:2005-07-24 21:23 出处:JR 责编:chinaitpower
              摘要:hbm2java和hbm2ddl工具的使用
hbm2java是根据映射文件自动生成java源文件

hbm2ddl 是根据映射文件自动生成数据库schema

XDoclet 根据带有XDoclet的标记的java源文件生成映射文件

Middlegen 根据数据库Schema自动生成映射文件

1'<class name = "mypack.customer">
   <meta attribute = "class-description">//指定下列为注释
     Repesents a single customer
     @author S
   </meta>
  </class>

2'<class name = "mypack.customer">
    <meta attribute = "extends">mypack.BusinessObject</meta>//指定类所继承的类
  </class>

3'<property name = "married" type ="boolean" column ="is_married">
    <meta attribute = "field-description">is the customer married </meta>//指定方法注释
  </property>

4'指定类、类的属性及类属性的get方法和set方法的修饰符可选:
   static 、 public 、 abstract 、final 、 private

<id name = "id" type = "int">
  <meta attribute = "scope-set">protected</meta>
  <generator class = "native">
</id>

5'指定在类的toString()方法返回的字符串中是否包含特定的属性

<property name ="name" type ="string" not-null = "true">
  <meta attribute ="use-in-tostring">true</meta>
</property>

////////////////<meta>的元素属性表

class-description//指定描述类的javaDoc

field-description//指定描述类的属性的javaDoc

interface//如果为true,表示生成接口而非类,默认为false

implements//指定类所实现的接口

extends//指定类继承的父类名

generated-class//重新指定生成的类名

scope-class//指定类的修饰符默认为public

scope-set//指定set方法的修饰符默认为public

scope-get//指定get方法的修饰符默认为public

scope-field//指定类的属性修饰符默认为private

use-in-toString//如果为true,表示在tostring方法中包含此属性

gen-property//如果为false不会在java类中生成此属性,默认为true

finder-method//指定find方法名

///////////////<column>制定数据库表

1'设定字段名、字段长度以及唯一性
<property name = "name" type ="string">
  <meta attribute ="use-in-tostring">true</meta>
  <column name ="name" length ="15" not-null ="true" unique ="true">
</property>//表示字段名为name长度为15不能为空具有唯一性

2'设定字段不为空,并且为这个字段设立检查约束。
<property name = "age" type ="int">
  <meta attribute = "field-description">How old is the customer</meta>
  <meta attribute = "use-in-tostring">true</meta>
  <column name = "age" check ="age > 10" not-null ="true">
</property>

3'建立索引
<property name = "registeredtime" type ="timestamp">
  <meta attribute ="field-description">When the customer was registered</meta>
  <meta attribute ="use-in-tostring">true</meta>
  <column name ="registerd_time" index = "idx_registerd_time" sql-type= "timestamp">
</property>

4'建立对应的字段类型
<property name = "description" type ="string">
  <meta attribute ="use-in-tostring">true</meta>
  <column name = "description" sql-type ="text">//根据相对应的数据库来定义字段的类型
</property>
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有