getCustomerIDs().add( customerId );
assertNull( "contact exists despite not being added", getFirstContact( customerId ) );
// check that cache was hit
SecondLevelCacheStatistics customerSlcs = sessionFactory()
.getStatistics()
.getSecondLevelCacheStatistics( Customer.class.getName() );
assertEquals( customerSlcs.getPutCount(), 1 );
assertEquals( customerSlcs.getElementCountInMemory(), 1 );
assertEquals( customerSlcs.getEntries().size(), 1 );
log.infof( "Add contact to customer {0}", customerId );
SecondLevelCacheStatistics contactsCollectionSlcs = sessionFactory()
.getStatistics()
.getSecondLevelCacheStatistics( Customer.class.getName() + ".contacts" );
assertEquals( 1, contactsCollectionSlcs.getPutCount() );
assertEquals( 1, contactsCollectionSlcs.getElementCountInMemory() );
assertEquals( 1, contactsCollectionSlcs.getEntries().size() );
final Contact contact = addContact( customerId );
assertNotNull( "contact returned by addContact is null", contact );
assertEquals(
"Customer.contacts cache was not invalidated after addContact", 0,
contactsCollectionSlcs.getElementCountInMemory()
);
assertNotNull( "Contact missing after successful add call", getFirstContact( customerId ) );
// read everyone's contacts