Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > XDoclet --hibernate标签 简单介绍
【标  题】:XDoclet --hibernate标签 简单介绍
【关键字】:XDoclet,--hibernate
【来  源】:http://blog.csdn.net/chenjyuj/archive/2007/04/11/1561342.aspx

XDoclet --hibernate标签 简单介绍

Your Ad Here

XDoclet in Action 下载地址: http://www.infoxa.com/asp/book/xxnr.asp?id=1570

 XDoclet实现基本原理是,通过在Java代码加入特定的JavaDoc tag,从而为其添加特定
的附加语义,之后通过XDoclet工具对代码中JavaDoc Tag进行分析,自动生成与代码对应
的配置文件,XDoclet。

血的教训,不要用 Key  当作变量名,不然无法自动生成数据库表。

@hibernate.class 

 

table 类对应的表名,默认值:当前类名
where 数据甄选条件,如果只需要处理库表中某些特定数据的时候,可通过此选项设定结果集限定条件。
dynamic-update

生成Update SQL时,仅包含发生变动的字段,默认值: false。dynamic-update="true"时,Update SQL 时候,只包括当前发生变化的字段(提高DB Update性能)。

dynamic-insert

生成Insert SQL时,仅包含非空(null)字段,默认值:false。  dynamic-insert="true" 时,Insert SQL 时候,只包括当前非空字段。(提高DB Insert性能)

discriminator-value 子类辨别标识,用于多态支持。     discriminator-value="1" discriminator-value 参数的目的是对多态提供支持。请参见下面关于@hibernate.discriminator的说明。
Proxy 代理类,默认值:空。     proxy=""  表明当前类不使用代理(Proxy)。代理类的作用是为Lazy.Loading提供支持
lazy Specifies the class itself to use for CGLIB proxy interface  默认:false                  lazy ="false"表示不采用延迟加载

@hibernate.discriminator  

@hibernate.discriminator(识别器) 用于提供多态支持。

column 用于区分各子类的字段名称。默认值:当前类名
type 对应的Hibernate类型
length 字段长度 

 

 

 

 注意下面的例子运行,应该是不能自动生成代码的,要把注释说明文档都删掉才可以,好象跟XDoclet文档有冲突,我以前有次就是写了些注释文档后就会出错。

/**
*
* @hibernate.class
* table="TUser"
* dynamic-update="true"
* dynamic-insert="true"
*
* @hibernate.discriminator column="user_type" type="integer"
*/

public class TUser implements Serializable {
......
}

//根类TUser 中,通过@hibernate.discriminator 指定了以"user_type"字段
//作为识别字段。
/**
* @hibernate.subclass
* discriminator-value="1"
*/

public class SysAdmin extends TUser {
......
}

/**
* @hibernate.subclass
* discriminator-value="2"
*/

public class SysOperator extends TUser {
......
}

//SysAdmin 和SysOperator 均继承自TUser,其discriminator-value 分别设置
//为"1"和"2",运行期Hibernate 在读取t_user 表数据时,会根据其user_type 字段进行
//判断,如果是1 的话则映射到SysAdmin类,如果是2 映射到SysOperator 类。

@hibernate.subclass,顾名思义,@hibernate.subclass与@hibernate.class
不同之处就在于,@hibernate.subclass 描述的是一个子类,实际上,这两个Tag
除去名称不同外,并没有什么区别。

@hibernate.id

描述POJO 中关键字段与数据库表主键之间的映射关系。

column 主键字段名,默认值:当前类名
type 字段类型。Hibernate总是使用对象型数据类型作为字段类型,如int对应Integer,因此这里将id设为基本类型[如int]以避免对
象创建的开销的思路是没有实际意义的,即使这里设置为基本类型,Hibernate内部还是会使用对象型数据对其进行处理,只是返回数据的时候再转换为基本类型而已。
length 字段长度 
unsaved-value 用于对象是否已经保存的判定值。
generator-class 主键产生方式(详见Hibernate QuickStart中关于MiddleGen的相关说明)取值可为下列值中的任意一个:
assigned,hilo,seqhilo, increment, identity, sequence, native, uuid.hex, uuid.string, foreign
 

 

 

 

 

 

 

 

 @hibernate.property

 

column 数据库表字段名,默认值:当前类名
type 字段类型
length 字段长度
not-null 字段是否允许为空
unique 字段是否唯一(是否允许重复值)
insert Insert 操作时是否包含本字段数据,默认:true
update Update  操作时是否包含本字段数据,默认:true

 @hibernate.parent

 Declares a parent reference

@hibernate.set

inverse If inverse collection
默认:false 。 inverse="false"表示主控方在 该类
table Defaults to role name: the name of the collection table (not used for one-to-many associations)
cascade Specifies which operations should be cascaded from the parent object to the associated object
Valid options are:
all,none,save-update,delete,all-delete-orphan,delete-orphan
sort Specify a sorted collection with natural sort order or a given comparator class
access The strategy Hibernate should use for accessing the property value.      Default value(s): property
Valid options are:       field,property,ClassName

 

 

 

 

 

 

 

 

@hibernate.one-to-one

 class  The name of the associated class
 property-ref  bi-directional reference to one-to-one table that holds the foreign key
 foreign-key  The name of the foreign key constraint to associate with this association.
 constrained  Is there a foreign key constraint
 outer-join  Enable outer-join fetching for this association when hibernate.use_outer_join is set
Default value(s):    auto
Valid options are:   true , false, auto
cascade  同
acess  同

 

@hibernate.many-to-one 

column The name of the mapped database table column
class The name of the associated class
not-null If the column is not nullable       Default value(s):   false 
insert Should the column appear in the SQL INSERT. Only applies for version >= 2.0
update Should the column appear in the SQL UPDATE. Only applies for version >= 2.0
cascade  同
acess  同

 

列举的是一些常用的,具体的可以去官方网站查找。

 

学习资源:

XDoclet 与Hibernate 映射

XDoclet @hibernate Tag Reference

 

在spring+hibernate3框架中使用HibernateDaoSupport应注意的问题:【上一篇】
Apache vs Sun:【下一篇】
【相关文章】
  • Xdoclet生成SessionBean 和 EntityBean代码(1)
  • Xdoclet生成SessionBean 和 EntityBean代码(2)
  • 用 hibernate 和 xdoclet 开发 数据库应用程序
  • 使用XDoclet生成代码
  • 在IntelliJ Idea中集成 Hibernate Xdoclet 开发
  • Hibernate学习(1)----Hibernate快速上手
  • 移:xdoclet2学习笔记
  • XDoclet简化Struts开发
  • 体验xdoclet+struts- -
  • ANT忠诚伴侣XDoclet下生成struts配置的基本任务手册- -
  • 【随机文章】
  • sp业务整体介绍
  • 设计模式简单代码之Flyweight模式
  • System V IPC 之 Message Queue
  • NDIS HOOK开发简单日志(3)-ndis版本
  • 第三节--定义一个类 -- PHP5的类与对象 [3]
  • 这次做portal的一些总结(一)
  • Direct3D Tutorial 6: Using Meshes
  • 14.9.3 Decimal comparison operators
  • 信息安全策略之四:Password Policy
  • 约瑟夫环C语言
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.