hibernate多表写问题
pojo:
Order
public class Order implements java.io.Serializable {
private int id; //订单自动编号
private int orderId;
private String goodsname; //商品名
private int goodsid; //商品ID
private int count; //购买的数量
private Float price; //单价
}
Orders:
public class Orders implements java.io.Serializable{
private int id; //编号
private String username;//用户名
private int userid; //用户编号
private Date submitTime; //订单提交时间
private Byte ispay; //是否已付款
private int orderscore; //订单积分
private java.util.Set ordere=new java.util.HashSet();
/** }
Orders.hbm.xml: Orders主键自动递增,one to many Order,
Order对应的Order表中orderid 为外键,references Orders(id);
<?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 package="com.qinge.pojo">
<class name="Orders" table="eOrders">
<id name="id" type="java.lang.Integer">
<column name="Id" /><generator type="java.lang.String">
<column name="Username" length="20" /></property>
<property name="userid" type="java.lang.Integer">
<column name="Userid" length="" /></property>
<property name="submitTime" type="java.lang.Date">
<column name="submitTime" length="" /></property>
<property name="ispay" type="java.lang.Byte">
<column name="Ispay" length="1" /></property>
<property name="orderscore" type="java.lang.Integer">
<column name="OrderScore" /></property>
<set name="ordere" inverse="true" lazy="false"><key>
<column name="Id" precision="10" scale="0" /></key>
<one-to-many /></set>
</class>
</hibernate-mapping>
像这个两个表插入数据市怎样保持关联?
我有疑惑:向Orders 表写数据时,id未知,向Order 表写数据是怎样确定orderId,以保证数据关联?
1 楼 szjiang 2008-05-06 cascade="all"