}
return sm;
}
// ACT_RUN
PersistenceCapable pc;
if (sm != null) {
if (sm.isDetached()) {
throw new ObjectExistsException(_loc.get("persist-detached", Exceptions.toString(obj)))
.setFailedObject(obj);
}
if (!sm.isEmbedded()) {
sm.persist();
_cache.persist(sm);
if ((action & OpCallbacks.ACT_CASCADE) != 0) {
sm.cascadePersist(call);
}
return sm;
}
// an embedded field; notify the owner that the value has
// changed by becoming independently persistent
sm.getOwner().dirty(sm.getOwnerIndex());
_cache.persist(sm);
pc = sm.getPersistenceCapable();
} else {
pc = assertPersistenceCapable(obj);
if (pc.pcIsDetached() == Boolean.TRUE) {
throw new ObjectExistsException(_loc.get("persist-detached", Exceptions.toString(obj)))
.setFailedObject(obj);
}
}
ClassMetaData meta = _repo.getMetaData(obj.getClass(), _loader, true);
if (fireEvent) {
fireLifecycleEvent(obj, null, meta, LifecycleEvent.BEFORE_PERSIST);
}
// create id for instance
if (id == null) {
int idType = meta.getIdentityType();
if (idType == ClassMetaData.ID_APPLICATION) {
id = ApplicationIds.create(pc, meta);
} else if (idType == ClassMetaData.ID_UNKNOWN) {
throw new UserException(_loc.get("meta-unknownid", meta));
} else {
id = StateManagerId.newInstance(this);
}
}
// make sure we don't already have the instance cached
checkForDuplicateId(id, obj, meta);
// if had embedded sm, null it
if (sm != null) {
pc.pcReplaceStateManager(null);
}
// create new sm
sm = newStateManagerImpl(id, meta);
if ((_flags & FLAG_ACTIVE) != 0) {