MutableCachedNode mutable = mutable();
mutable.setProperty(cache, session.propertyFactory().create(JcrLexicon.PRIMARY_TYPE, newPrimaryTypeName));
if (wasReferenceable && !isReferenceable()) {
// Need to remove the 'jcr:uuid' reference ...
mutable.removeProperty(cache, JcrLexicon.UUID);
} else if (isReferenceable() && !mutable.hasProperty(JcrLexicon.UUID, cache)) {
mutable.setProperty(cache, session.propertyFactory().create(JcrLexicon.UUID, getIdentifier()));
}
// And auto-create any properties that are defined by the new primary type ...