Hibernate hbm2java meta标签学习

来源:互联网 发布:linux谁开发的 编辑:程序博客网 时间:2024/05/17 23:03

hbm2java 从字面意思就是从hbm配置文件生成java源代码文件
在hbm2java中通过meta标签来确认生成的持久化类的java代码

以下是几种不同的hbm配置文件中meta标签的使用方法

1.指定描述类的JavaDoc

<class name="mypack.Customer">  <meta attribute="class-description">   Represents a single customer.   @author SH  </meta></class>

在这个配置文件中我们增加了一个meta元素,这个元素的作用表示在类中添加描述类的JavaDoc,效果展示

/** * *  Represents a single custome *  @author SH **/ public class Customer implements Serializable

2.指定类所继承的类

<class name="mypack.Customer">  <meta attribute="extends">mypack.BussinessObject</meta></class>

显而易见这个元素表示了customer类继承了BussinessObject类

3.指定描述类属性的JavaDoc

<property name="married" type="boolean" column="IS_MARRIED">     <meta attribute="field-description">Is the customer married</meta></property>

meta元素还有很多特殊的属性,下面展示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-filed 指定类的属性修饰符,默认为public use-in-tostring 如果为true,表示在tostring()方法中包含此属性 gen-property 如果为false,不会再Java类中生成此属性,默认为true

注:通过hbm2java生成的持久化类都会实现serializable接口

0 0