我有这样一段代码:
Transaction tx = session.beginTransaction();
Users user = new Users();
user.setName( "john ");
Cards card = new Cards();
card.setCardNum( "9923923 ");
card.setUsers(user);//设置关联的对象
user.getCardses().add(card);
session.save(user); //通过主控对象级联更新
tx.commit();
这段代码,没有问题,先设置好关联对象,然后通过主控对象级联更新。那么这样的代码:
Transaction tx = session.beginTransaction();
Users user = new Users();
user.setName( "john ");
Cards card = new Cards();
card.setCardNum( "9923923 ");
session.save(user);
card.setUsers(user);
user.getCardses().add(card);