Hibernate關(guān)聯(lián)映射1
public
class District implements java.io.Serializable
{
//區(qū)
Long id;
String name;
/**
*/
District(){
}
//
}
public
class Street implements java.io.Serializable
{
//街道
Long id;
District district;
String name;
/**
*/
Street(){
}
return
}
district)
{
this.district
=
district;
}
//
}
<hibernate-mapping>
table="street”>
<id name="id" type="
<column name="id" />
<generator class="native" />
</id>
<
name="district"
class="cn.jbit.houserent.bean.District">
<column name="
</
<property name="name" type="
<column name="
length="50" not-null="true" />
</property>
</class>
</hibernate-mapping>
元素的常用屬性
屬性 | 含義和作用 | 必須 | 默認(rèn)值 |
name | 映射類屬性的名稱 | Y | |
class | 關(guān)聯(lián)類的完全限定名 | N | |
column | 關(guān)聯(lián)的字段 | N | |
not-null | 設(shè)置關(guān)聯(lián)的字段的值是否可以為空 | N | false |
lazy | 指定關(guān)聯(lián)對(duì)象是否使用延遲加載以及延遲加載的策略 | N | proxy |
fetch | 設(shè)置抓取數(shù)據(jù)的策略 | N | select |
單向多對(duì)一,在“多”的一方,設(shè)置“一”的引用,再配置<many-to-one>標(biāo)簽
“一”的一方不變
posted on 2012-04-22 15:48 hantai 閱讀(68) 評(píng)論(0) 編輯 收藏