@Test
public void should_allow_dynamic_schema_update() throws Exception {
//Given
Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
final Session session = CassandraEmbeddedServerBuilder
.noEntityPackages().withKeyspaceName("schema_dynamic_update")
.cleanDataFilesAtStartup(true)
.buildNativeSessionOnly();
session.execute("DROP TABLE IF EXISTS new_simple_field");
session.execute("DROP INDEX IF EXISTS field_index");
session.execute("CREATE TABLE new_simple_field(id bigint PRIMARY KEY, existing_field text)");
session.execute("CREATE INDEX field_index ON schema_dynamic_update.new_simple_field(existing_field)");
//When
final PersistenceManagerFactory pmf = PersistenceManagerFactoryBuilder.builder(session.getCluster())
.withNativeSession(session)
.withEntities(Arrays.<Class<?>>asList(EntityWithNewSimpleField.class))
.enableSchemaUpdate(false)
.enableSchemaUpdateForTables(ImmutableMap.of("schema_dynamic_update.new_simple_field", true))
.relaxIndexValidation(true)
.build();
final PersistenceManager pm = pmf.createPersistenceManager();
pm.insert(new EntityWithNewSimpleField(id, "existing", "new"));
//Then
final EntityWithNewSimpleField found = pm.find(EntityWithNewSimpleField.class, id);
assertThat(found).isNotNull();
assertThat(found.getUnmappedField()).isEqualTo("UNMAPPED");
assertThat(pm.getProxy(EntityWithNewSimpleField.class, id).getUnmappedField()).isEqualTo("UNMAPPED");
session.close();
}