XDoclet --hibernate标签 简单介绍

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提供支持
lazySpecifies 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

inverseIf inverse collection
默认:false 。 inverse="false"表示主控方在 该类
tableDefaults to role name: the name of the collection table (not used for one-to-many associations)
cascadeSpecifies 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
sortSpecify a sorted collection with natural sort order or a given comparator class
accessThe 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 

columnThe name of the mapped database table column
classThe name of the associated class
not-nullIf the column is not nullable       Default value(s):   false 
insertShould the column appear in the SQL INSERT. Only applies for version >= 2.0
updateShould the column appear in the SQL UPDATE. Only applies for version >= 2.0
cascade 同
acess 同

 

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

 

学习资源:

XDoclet 与Hibernate 映射

XDoclet @hibernate Tag Reference

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值