在本文中主要实现数据的级联插入,下面模拟的场景是,用户有多个订单,在插入用户的时候,将用户的订单添加到订单表中。
下面是User 和 Order两个pojo类的代码
[java]
public class Order {
private int id;
private int whoid; // thi id of the order's User
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getWhoid() {
return whoid;
}
public void setWhoid(int whoid) {
this.whoid = whoid;
}
}
public class Order {
private int id;