/// <summary>
        /// The given save-update event named a transient entity.
        /// Here, we will perform the save processing.
        /// </summary>
        /// <param name="event">The save event to be handled. </param>
        /// <returns> The entity's identifier after saving. </returns>
        protected virtual object EntityIsTransient(SaveOrUpdateEvent @event)
        {
            log.Debug("saving transient instance");

            IEventSource source      = @event.Session;
            EntityEntry  entityEntry = @event.Entry;

            if (entityEntry != null)
            {
                if (entityEntry.Status == Status.Deleted)
                {
                    source.ForceFlush(entityEntry);
                }
                else
                {
                    throw new AssertionFailure("entity was persistent");
                }
            }

            object id = SaveWithGeneratedOrRequestedId(@event);

            source.PersistenceContext.ReassociateProxy(@event.Entity, id);

            return(id);
        }
        /// <summary>
        /// Prepares the save call by checking the session caches for a pre-existing
        /// entity and performing any lifecycle callbacks.
        /// </summary>
        /// <param name="entity">The entity to be saved. </param>
        /// <param name="id">The id by which to save the entity. </param>
        /// <param name="persister">The entity's persister instance. </param>
        /// <param name="useIdentityColumn">Is an identity column being used? </param>
        /// <param name="anything">Generally cascade-specific information. </param>
        /// <param name="source">The session from which the event originated. </param>
        /// <param name="requiresImmediateIdAccess">
        /// does the event context require
        /// access to the identifier immediately after execution of this method (if
        /// not, post-insert style id generators may be postponed if we are outside
        /// a transaction).
        /// </param>
        /// <returns>
        /// The id used to save the entity; may be null depending on the
        /// type of id generator used and the requiresImmediateIdAccess value
        /// </returns>
        protected virtual object PerformSave(object entity, object id, IEntityPersister persister, bool useIdentityColumn, object anything, IEventSource source, bool requiresImmediateIdAccess)
        {
            if (log.IsDebugEnabled())
            {
                log.Debug("saving {0}", MessageHelper.InfoString(persister, id, source.Factory));
            }

            EntityKey key;

            if (!useIdentityColumn)
            {
                key = source.GenerateEntityKey(id, persister);
                object old = source.PersistenceContext.GetEntity(key);
                if (old != null)
                {
                    if (source.PersistenceContext.GetEntry(old).Status == Status.Deleted)
                    {
                        source.ForceFlush(source.PersistenceContext.GetEntry(old));
                    }
                    else
                    {
                        throw new NonUniqueObjectException(id, persister.EntityName);
                    }
                }
                if (!(id is DelayedPostInsertIdentifier))
                {
                    persister.SetIdentifier(entity, id);
                }
            }
            else
            {
                key = null;
            }

            if (InvokeSaveLifecycle(entity, persister, source))
            {
                return(id);                //EARLY EXIT
            }
            return(PerformSaveOrReplicate(entity, key, persister, useIdentityColumn, anything, source, requiresImmediateIdAccess));
        }
		/// <summary> 
		/// Prepares the save call by checking the session caches for a pre-existing
		/// entity and performing any lifecycle callbacks. 
		/// </summary>
		/// <param name="entity">The entity to be saved. </param>
		/// <param name="id">The id by which to save the entity. </param>
		/// <param name="persister">The entity's persister instance. </param>
		/// <param name="useIdentityColumn">Is an identity column being used? </param>
		/// <param name="anything">Generally cascade-specific information. </param>
		/// <param name="source">The session from which the event originated. </param>
		/// <param name="requiresImmediateIdAccess">
		/// does the event context require
		/// access to the identifier immediately after execution of this method (if
		/// not, post-insert style id generators may be postponed if we are outside
		/// a transaction). 
		/// </param>
		/// <returns> 
		/// The id used to save the entity; may be null depending on the
		/// type of id generator used and the requiresImmediateIdAccess value
		/// </returns>
		protected virtual object PerformSave(object entity, object id, IEntityPersister persister, bool useIdentityColumn, object anything, IEventSource source, bool requiresImmediateIdAccess)
		{
			if (log.IsDebugEnabled)
			{
				log.Debug("saving " + MessageHelper.InfoString(persister, id, source.Factory));
			}

			EntityKey key;
			if (!useIdentityColumn)
			{
				key = source.GenerateEntityKey(id, persister);
				object old = source.PersistenceContext.GetEntity(key);
				if (old != null)
				{
					if (source.PersistenceContext.GetEntry(old).Status == Status.Deleted)
					{
						source.ForceFlush(source.PersistenceContext.GetEntry(old));
					}
					else
					{
						throw new NonUniqueObjectException(id, persister.EntityName);
					}
				}
				persister.SetIdentifier(entity, id, source.EntityMode);
			}
			else
			{
				key = null;
			}

			if (InvokeSaveLifecycle(entity, persister, source))
			{
				return id; //EARLY EXIT
			}
			return PerformSaveOrReplicate(entity, key, persister, useIdentityColumn, anything, source, requiresImmediateIdAccess);
		}