Hibernate關聯映射1
public
class District implements java.io.Serializable
{
//區
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>
元素的常用屬性
屬性 | 含義和作用 | 必須 | 默認值 |
name | 映射類屬性的名稱 | Y | |
class | 關聯類的完全限定名 | N | |
column | 關聯的字段 | N | |
not-null | 設置關聯的字段的值是否可以為空 | N | false |
lazy | 指定關聯對象是否使用延遲加載以及延遲加載的策略 | N | proxy |
fetch | 設置抓取數據的策略 | N | select |
單向多對一,在“多”的一方,設置“一”的引用,再配置<many-to-one>標簽
“一”的一方不變