XDoclet in Action 下载地址: http://www.infoxa.com/asp/book/xxnr.asp?id=1570
XDoclet实现基本原理是,通过在Java代码加入特定的JavaDoc tag,从而为其添加特定
的附加语义,之后通过XDoclet工具对代码中JavaDoc Tag进行分析,自动生成与代码对应
的配置文件,XDoclet。
血的教训,不要用 Key 当作变量名,不然无法自动生成数据库表。
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(识别器) 用于提供多态支持。
column | 用于区分各子类的字段名称。默认值:当前类名 |
type | 对应的Hibernate类型 |
length | 字段长度 |
注意下面的例子运行,应该是不能自动生成代码的,要把注释说明文档都删掉才可以,好象跟XDoclet文档有冲突,我以前有次就是写了些注释文档后就会出错。






































@hibernate.subclass,顾名思义,@hibernate.subclass与@hibernate.class
不同之处就在于,@hibernate.subclass 描述的是一个子类,实际上,这两个Tag
除去名称不同外,并没有什么区别。
描述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 |
column | 数据库表字段名,默认值:当前类名 |
type | 字段类型 |
length | 字段长度 |
not-null | 字段是否允许为空 |
unique | 字段是否唯一(是否允许重复值) |
insert Insert | 操作时是否包含本字段数据,默认:true |
update Update | 操作时是否包含本字段数据,默认:true |
Declares a parent reference
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 |
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 | 同 |
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