表 15.6. 支持的meta标签
| 属性 |
说明 |
class-description
插入到类的javadoc说明去
field-description
插入到field/property的javadoc说明去
interface
如果是true,生成interface而非class
implements
类要实现的接口
extends
类要继承的超类(若是subclass,则忽略该属性)
generated-class
重新指定要生成的类名
scope-class
class的scope
scope-set
set方法的scope
scope-get
get方法的scope
scope-field
实际属性字段(field)的scope
use-in-tostring
在toString()中包含此属性
implement-equals
在这个类中包含equals()和hashCode()方法
use-in-equals
在equals()和hashCode() 方法中包含此属性
bound
为属性增加propertyChangeListener支持
constrained
为属性增加vetoChangeListener支持
gen-property
如果是false,不会生成属性(谨慎使用)
property-type
覆盖属性的默认值.如果值是标签,则指定一个具体的类型而非Object(Use this with any tag's to specify the concrete type instead of just Object.)
class-code
在类的最后会插入的额外代码
extra-import
在所有的import后面会插入的额外的import
finder-method
参见下面的"Basic finder generator"
session-method
参见下面的"Basic finder generator"
通过<meta>标签定义的属性在一个hbm.xml文件中是默认"继承"的。
这究竟是什么意思?如果你希望你所有的类都实现IAuditable接口,那么你只需要加一个<meta attribute="implements">IAuditable</meta> 在你hml.xml文件的开头,就在<hibernate-mapping>后面。现在所有在hbm.xml文件中定义的类都会实现IAuditable了!(除了那些也特别指定了"implements"元属性的类,因为本地指定的元标签总是会覆盖任何继承的元标签)。
注意,这条规则对所有 的<meta>标签都有效。也就是说它可以用来指定所有的字段都被声明成protected的,而非默认的private。这可以通过在<class>后面<meta attribute="scope-field">protected</meta>指定,那么这个类所有的field都会变成protected。
如果你不想让<meta>标签继承,你可以简单的在标签属性上指明inherit="false",比如<meta attribute="scope-class" inherit="false">public abstract</meta>,这样"class-scope"就只会对当前类起作用,不会对其子类生效。 进入讨论组讨论。
15.2.3. 基本的finder生成器(Basic finder generator)
目前可以让hbm2java为Hibernate属性生成基本的finder。这需要在hbm.xml文件中做两件事情。
首先是要标记出你希望生成finder的字段。你可以通过在property标签中的meta 块来定义:
<property name="name" column="name" type="string">
<meta attribute="finder-method">findByName</meta>
</property>
上一篇: JAVA加密解密---自定义类加载器应用
下一篇: JBoss下的EJB3开发无状态会话Bean
|