w100224
2017-05-15 15:27
采纳率: 85.7%
浏览 1.8k
已采纳

hibernate一对多级联保存机制是什么

Configuration configuration = new Configuration().configure();
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();

    Order order = new Order();
    order.setOrderName("订单2");

    Ticket ticket = new Ticket("优惠券1",order);
    Ticket ticket1 = new Ticket("优惠券2",order);
    order.getTickets().add(ticket);
    order.getTickets().add(ticket1);

    session.save(order);

    transaction.commit();
    session.close();
    sessionFactory.close();
 我明明只执行了订单order的save操作,其中一个order对应多个ticket优惠券,为什么输出的sql中 是执行了对应的三个insert语句后,又执行了两次ticket优惠券的update?这里的update语句是干啥的,一对多级联保存机制是什么

这是打印的sql:
Hibernate:
insert
into
bc_order
(orderName)
values
(?)
Hibernate:
insert
into
bc_ticket
(ticketName, orderId)
values
(?, ?)
Hibernate:
insert
into
bc_ticket
(ticketName, orderId)
values
(?, ?)
Hibernate:
update
bc_ticket
set
orderId=?,
p_index=?
where
ticketId=?
Hibernate:
update
bc_ticket
set
orderId=?,
p_index=?
where
ticketId=?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新