validateElementForWriting(sm, element, null);
Object o = get(sm, index);
getSpecialization().set(element, index, sm, this);
CollectionMetaData collmd = ownerMemberMetaData.getCollection();
boolean dependent = collmd.isDependentElement();
if (ownerMemberMetaData.isCascadeRemoveOrphans())
{
dependent = true;
}
if (dependent && !collmd.isEmbeddedElement() && allowDependentField)
{
if (o != null && !contains(sm, o))
{
// Delete the element if it is dependent and doesnt have a duplicate entry in the list
sm.getExecutionContext().deleteObjectInternal(o);