您好,登錄后才能下訂單哦!
這篇文章主要介紹“Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記”,在日常操作中,相信很多人在Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
1.Hibernate元數(shù)據(jù) 使用 XDoclet 標(biāo)記
很多Hibernate使用者更喜歡使用XDoclet@hibernate.tags將映射信息直接嵌入到源代碼中。我們不會(huì)在本文檔中涉及這個(gè)方法,因?yàn)閲?yán)格說來,這屬于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" */ public float getWeight() { return weight; } void setWeight(float weight) { this.weight = weight; } /** * @hibernate.property * column="COLOR" * not-null="true" */ public Color getColor() { return color; } void setColor(Color color) { this.color = color; } /** * @hibernate.set * inverse="true" * order-by="BIRTH_DATE" * @hibernate.collection-key * column="PARENT_ID" * @hibernate.collection-one-to-many */ public Set getKittens() { return kittens; } void setKittens(Set kittens) { this.kittens = kittens; } // addKitten not needed by Hibernate public void addKitten(Cat kitten) { kittens.add(kitten); } /** * @hibernate.property * column="SEX" * not-null="true" * update="false" */ public char getSex() { return sex; } void setSex(char sex) { this.sex=sex; } }
參考Hibernate網(wǎng)站更多的Xdoclet和Hibernate的例子
2. Hibernate元數(shù)據(jù)使用 JDK 5.0 的注解(Annotation)
JDK 5.0 在語言級別引入了 XDoclet 風(fēng)格的標(biāo)注,并且是類型安全的,在編譯期進(jìn)行檢查。這一機(jī)制比XDoclet的注解更為強(qiáng)大,有更好的工具和IDE支持。例如, IntelliJ IDEA,支持JDK 5.0注解的自動(dòng)完成和語法高亮 。EJB規(guī)范的新修訂版(JSR-220)使用 JDK 5.0的注解作為entity beans的主要元數(shù)據(jù)(metadata)機(jī)制。
Hibernate 3 實(shí)現(xiàn)了JSR-220 (the persistence API)的EntityManager,支持通過Hibernate Annotations包定義映射元數(shù)據(jù)。這個(gè)包作為單獨(dú)的部分下載,支持EJB3 (JSR-220)和Hibernate3的元數(shù)據(jù)。
這是一個(gè)被注解為EJB entity bean 的POJO類的例子
@Entity(access = AccessType.FIELD) public class Customer implements Serializable { @Id; Long id; String firstName; String lastName; Date birthday; @Transient Integer age; @Embedded private Address homeAddress; @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name="CUSTOMER_ID") Set<Order> orders; // Getter/setter and business methods }
到此,關(guān)于“Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。