百度空间 | 百度首页 
 
查看文章
 
hbm2java,hbm2ddl,XDoclet ,Middlegen 工具使用
2008-11-11 16:47

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>



类别:Java | 添加到搜藏 | 浏览() | 评论 (1)
 
最近读者:
 
网友评论:
1
2009-03-17 21:58 | 回复
那两个工具我怎么没找到呀 ?
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu