// Given, When
Husband husband = new Husband( "alex" );
husband.setName( "Alex" );
session.persist( husband );
Wife wife = new Wife( "bea" );
wife.setName( "Bea" );
husband.setWife( wife );
wife.setHusband( husband );
session.persist( wife );
transaction.commit();
session.clear();
transaction = session.beginTransaction();
// Then
assertDbObject(
session.getSessionFactory(),
// collection
"Wife",
// query
"{ '_id' : 'bea' }",
// expected
"{ " +
"'_id' : 'bea', " +
"'name' : 'Bea'," +
"'husband' : 'alex'" +
"}"
);
assertDbObject(
session.getSessionFactory(),
// collection
"Husband",
// query
"{ '_id' : 'alex' }",
// expected
"{ " +
"'_id' : 'alex', " +
"'name' : 'Alex'," +
"'wife' : 'bea'" +
"}"
);
// Clean-Up
husband = (Husband) session.get( Husband.class, husband.getId() );
wife = (Wife) session.get( Wife.class, wife.getId() );
session.delete( wife );
session.delete( husband );
transaction.commit();
session.close();