产品类别与产品构成一对多关系,在Hibernate映射中:
ProductCategory.hbm.xml
<
set
name
=
"
products
"
sort
=
"
unsorted
"
cascade
=
"
save-update,delete
"
inverse
=
"
true
"
lazy
=
"
false
"
>
< key column = " product_category_id_fk " />
< one - to - many class = " com.astartech.model.Product " />
</ set >
< key column = " product_category_id_fk " />
< one - to - many class = " com.astartech.model.Product " />
</ set >
对应的,JavaBean中:
ProductCategory.java
........
private Set < Product > products = new HashSet < Product > ();
........
private Set < Product > products = new HashSet < Product > ();
........
相对应的产品与产品类别构成多对一关系,在Hibernate映射中:
Product.hbm.xml
<
many
-
to
-
one name
=
"
productCategory
"
class
=
"
com.astartech.model.ProductCategory
"
outer
-
join
=
"
true
"
lazy
=
"
false
"
>
< column name = " product_category_id_fk " not - null = " true " />
</ many - to - one >
< column name = " product_category_id_fk " not - null = " true " />
</ many - to - one >
对应的,JavaBean中:
Product.java
.......
private ProductCategory productCategory;
.......
private ProductCategory productCategory;
.......
在产品与产品详细信息构成一对一关系,在Hibernate映射中
Product.hbm.xml
<
one
-
to
-
one name
=
"
productDetail
"
class
=
"
com.astartech.model.ProductDetail
"
outer - join = " true " cascade = " all " lazy = " false " />
outer - join = " true " cascade = " all " lazy = " false " />
对应的,JavaBean中
Product.java
.......
private ProductDetail productDetail;
.......
private ProductDetail productDetail;
.......
在产品详细信息与产品构成一对一关系,在Hibernate映射中
ProductDetail.hbm.xml
<
one
-
to
-
one
class
=
"
com.astartech.model.Product
"
name
=
"
product
"
constrained
=
"
true
"
lazy
=
"
false
"
/>
对应的,JavaBean中
ProductDetail.java
......
private Product product;
......
private Product product;
......