Hibernate元數據有很多值得學習的地方,這裏我們主要介紹其他Hibernate元數據(Metadata),包括介紹使用XDoclet 標記等方面
其他Hibernate元數據(Metadata),XML 並不適用於所有人, 因此有其他定義Hibernate O/R 映射元數據(metadata)的方法。
1.Hibernate元數據 使用 XDoclet 標記
很多Hibernate使用者更喜歡使用[email protected]將映射信息直接嵌入到源代碼中。我們不會在本文檔中涉及這個方法,因爲嚴格說來,這屬於XDoclet的一部分。然而,我們包含了如下使用XDoclet映射的Cat類的例子。
package eg;
import java.util.Set;
import java.util.Date;
/**
* @hibernate.class
* table
=“CATS”
*/
public class Cat {
private Long id; // identifier
private Date birthdate;
private Cat mother;
private Set kittens
private Color color;
private char sex;
private float weight;
/*
* @hibernate.id
* generator-class
=“native”
* column
=“CAT_ID”
*/
public Long getId() {
return id;
}
private void setId(Long id) {
this.id
=id;
}
/**
* @hibernate.many-to-one
* column
=“PARENT_ID”
*/
public Cat getMother() {
return mother;
}
void setMother(Cat mother) {
this.mother
= mother;
}
/**
* @hibernate.property
* column
=“BIRTH_DATE”
*/
public Date getBirthdate() {
return birthdate;
}
void setBirthdate(Date date) {
birthdate
= date;
}
/**
* @hibernate.property
* column
=“WEIGHT”
*/