@@ -0,0 +1,3199 @@
+package arez.integration.references;%0A%0Aimport arez.Arez;%0Aimport arez.Disposable;%0Aimport arez.Observer;%0Aimport arez.annotations.ArezComponent;%0Aimport arez.annotations.Observable;%0Aimport arez.annotations.Reference;%0Aimport arez.annotations.ReferenceId;%0Aimport arez.annotations.Repository;%0Aimport arez.component.Identifiable;%0Aimport arez.component.TypeBasedLocator;%0Aimport arez.integration.AbstractArezIntegrationTest;%0Aimport java.util.HashMap;%0Aimport java.util.Objects;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0Aimport javax.annotation.Nonnull;%0Aimport org.testng.annotations.Test;%0Aimport static org.testng.Assert.*;%0A%0Apublic class ReferenceOutsideTransactionIntegrationTest%0A  extends AbstractArezIntegrationTest%0A%7B%0A  @Test%0A  public void scenario()%0A    throws Throwable%0A  %7B%0A    final ReferenceOutsideTransactionIntegrationTest_Model2Repository repository =%0A      ReferenceOutsideTransactionIntegrationTest_Model2Repository.newRepository();%0A%0A    final TypeBasedLocator locator = new TypeBasedLocator();%0A    Arez.context().registerLocator( locator );%0A%0A    final AtomicInteger findCallCount = new AtomicInteger();%0A    final HashMap%3CObject, Model2%3E entities = new HashMap%3C%3E();%0A    locator.registerLookup( Model2.class, id -%3E %7B%0A      findCallCount.incrementAndGet();%0A      return entities.get( id );%0A    %7D );%0A%0A    final Model2 model2a = repository.create();%0A    final Model2 model2b = repository.create();%0A    final Object model2aId = Objects.requireNonNull( Identifiable.getArezId( model2a ) );%0A    final Object model2bId = Objects.requireNonNull( Identifiable.getArezId( model2b ) );%0A    entities.put( model2aId, model2a );%0A    entities.put( model2bId, model2b );%0A%0A    assertEquals( findCallCount.get(), 0 );%0A    final Model1 model1 = Model1.create( model2aId );%0A    assertEquals( findCallCount.get(), 1 );%0A%0A    assertEquals( model1.getModel2(), model2a );%0A%0A    assertEquals( findCallCount.get(), 1 );%0A%0A    final AtomicInteger observerCallCount = new AtomicInteger();%0A    final Observer observer = autorun( () -%3E %7B%0A      model1.getModel2();%0A      observerCallCount.incrementAndGet();%0A    %7D );%0A%0A    assertEquals( observerCallCount.get(), 1 );%0A    assertEquals( findCallCount.get(), 1 );%0A%0A    safeAction( () -%3E model1.setModel2Id( model2bId ) );%0A%0A    assertEquals( observerCallCount.get(), 2 );%0A    assertEquals( findCallCount.get(), 2 );%0A%0A    assertEquals( model1.getModel2(), model2b );%0A%0A    assertEquals( observerCallCount.get(), 2 );%0A    assertEquals( findCallCount.get(), 2 );%0A  %7D%0A%0A  @ArezComponent%0A  static abstract class Model1%0A  %7B%0A    @Nonnull%0A    private Object _model2Id;%0A%0A    static Model1 create( @Nonnull final Object model2Id )%0A    %7B%0A      return new ReferenceOutsideTransactionIntegrationTest_Arez_Model1( model2Id );%0A    %7D%0A%0A    Model1( @Nonnull final Object model2Id )%0A    %7B%0A      _model2Id = model2Id;%0A    %7D%0A%0A    @Reference%0A    abstract Model2 getModel2();%0A%0A    @ReferenceId%0A    @Observable( readOutsideTransaction = true )%0A    @Nonnull%0A    Object getModel2Id()%0A    %7B%0A      return _model2Id;%0A    %7D%0A%0A    void setModel2Id( @Nonnull Object model2Id )%0A    %7B%0A      _model2Id = model2Id;%0A    %7D%0A  %7D%0A%0A  @Repository%0A  @ArezComponent( allowEmpty = true )%0A  static abstract class Model2%0A  %7B%0A  %7D%0A%7D%0A

Add test for reading outside a transaction