Java代码
// in the first session
Cat cat = (Cat); firstSession.load(Cat.class, catId);;
Cat potentialMate = new Cat();;
firstSession.save(potentialMate);;
// in a higher tier of the application
cat.setMate(potentialMate);;
// later, in a new session
secondSession.update(cat);; // update cat
secondSession.update(mate);; // update mate
// in the first session Cat cat = (Cat); firstSession.load(Cat.class, catId);; Cat potentialMate = new Cat();;
firstSession.save(potentialMate);; // in a higher tier of the application cat.setMate(potentialMate);; // later, in a
new session secondSession.update(cat);; // update cat secondSession.update(mate);; // update mate