package model;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
//订单
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Double total;
private String realname;
private String address;
private String postcode;
private String phone;
private Set<Product> products=new HashSet<Product>();
public Order(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
}
order.hbm.xml如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.Order" table="orders" >
<id name="id" type="java.lang.Integer">
<column name="ID" precision="8"></column>
<generator class="increment">
</generator>
</id>
<property name="total" column="total" type="java.lang.Double"></property>
<property name="realname" column="realname" type="java.lang.String"></property>
<property name="address" column="address" type="java.lang.String"></property>
<property name="postcode" column="postcode" type="java.lang.String"></property>
<property name="phone" column="phone" type="java.lang.String"></property>
<set name="products" table="orderitem" outer-join="true">
<key column="order_id"></key>
<many-to-many class="model.Product" column="product_id"></many-to-many>
</set>
</class>
</hibernate-mapping>
package model;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
//产品
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private Double price;
private String description;
private Set<Order> orders=new HashSet<Order>(0);
public Product(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<Order> getOrders() {
return orders;
}
public void setOrders(Set<Order> orders) {
this.orders = orders;
}
}
Product.hbm.xml如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.Product" table="product" >
<id name="id" type="java.lang.Integer">
<column name="ID" precision="8"></column>
<generator class="increment">
</generator>
</id>
<property name="name" column="name" length="200"></property>
<property name="price" column="price" precision="8" scale="2"></property>
<property name="description" column="description" length="2000"></property>
<set name="orders" table="orderitem" outer-join="true">
<key column="product_id"></key>
<many-to-many class="model.Order" column="ORDER_ID"></many-to-many>
</set>
</class>
</hibernate-mapping>