這篇文章主要介紹“Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記”,在日常操作中,相信很多人在Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
目前創(chuàng)新互聯(lián)已為上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、永善網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
1.Hibernate元數(shù)據(jù) 使用 XDoclet 標(biāo)記
很多Hibernate使用者更喜歡使用XDoclet@hibernate.tags將映射信息直接嵌入到源代碼中。我們不會在本文檔中涉及這個方法,因為嚴格說來,這屬于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)注,并且是類型安全的,在編譯期進行檢查。這一機制比XDoclet的注解更為強大,有更好的工具和IDE支持。例如, IntelliJ IDEA,支持JDK 5.0注解的自動完成和語法高亮 。EJB規(guī)范的新修訂版(JSR-220)使用 JDK 5.0的注解作為entity beans的主要元數(shù)據(jù)(metadata)機制。
Hibernate 3 實現(xiàn)了JSR-220 (the persistence API)的EntityManager,支持通過Hibernate Annotations包定義映射元數(shù)據(jù)。這個包作為單獨的部分下載,支持EJB3 (JSR-220)和Hibernate3的元數(shù)據(jù)。
這是一個被注解為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") Setorders; // Getter/setter and business methods }
到此,關(guān)于“Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
本文標(biāo)題:Hibernate元數(shù)據(jù)怎么使用XDoclet標(biāo)記
網(wǎng)站地址:http://weahome.cn/article/ijcspd.html