// Retrieve a Bar
simpleBarRequest().findSimpleBarById("999L").fire(new Receiver<SimpleBarProxy>() {
@Override
public void onSuccess(SimpleBarProxy response) {
final SimpleBarProxy barProxy = checkSerialization(response);
// Retrieve a Foo
simpleFooRequest().findSimpleFooById(999L).fire(new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy fooProxy) {
fooProxy = checkSerialization(fooProxy);
SimpleFooRequest context = simpleFooRequest();
fooProxy = context.edit(fooProxy);
// Make the Foo point to the Bar
fooProxy.setBarField(barProxy);
fooProxy.setUserName("Hello");
fooProxy.setByteField((byte) 55);
context.persistAndReturnSelf().using(fooProxy).with("barField").fire(
new Receiver<SimpleFooProxy>() {
@Override
public void onSuccess(SimpleFooProxy received) {
received = checkSerialization(received);
// Check that Foo points to Bar
assertNotNull(received.getBarField());
assertEquals(barProxy.stableId(), received.getBarField().stableId());
assertEquals("Hello", received.getUserName());
assertTrue(55 == received.getByteField());
// Unset the association
SimpleFooRequest context = simpleFooRequest();