This project is read-only.

Two step site data import

Topics: Developer Forum
Sep 23, 2008 at 1:32 PM


I'm have two pages, that are referencing each other (cyclic reference) through details properties.
May be it's looks incorrect, but it's works fine except importing, which is failed because trying to save an object with property referencing other which is not save yet.

Is it possible to divide import process into the two steps, first is saving ContentItem itself, and the second is saving it's detail properties to allow using cicular references?

Here is the exception details:

object references an unsaved transient instance - save the transient instance before flushing: N2.ContentItem

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: NHibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: N2.ContentItem

Source Error: 

Line 24: 		{
Line 25:             if(isOriginator && !transaction.WasCommitted && !transaction.WasRolledBack)
Line 26: transaction.Commit();Line 27: 		}
Line 28: 

Source File: c:\ProjectsExtern\N2\N2-\src\N2\Persistence\NH\NHTransaction.cs    Line: 26 

Stack Trace: 

[TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: N2.ContentItem]
   NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session) +288
   NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session) +95
   NHibernate.Type.ManyToOneType.IsDirty(Object old, Object current, Boolean[] checkable, ISessionImplementor session) +114
   NHibernate.Type.TypeFactory.FindDirty(StandardProperty[] properties, Object[] x, Object[] y, Boolean[][] includeColumns, Boolean anyUninitializedProperties, ISessionImplementor session) +133
   NHibernate.Persister.Entity.AbstractEntityPersister.FindDirty(Object[] currentState, Object[] previousState, Object entity, ISessionImplementor session) +63
   NHibernate.Event.Default.DefaultFlushEntityEventListener.DirtyCheck(FlushEntityEvent event) +159
   NHibernate.Event.Default.DefaultFlushEntityEventListener.IsUpdateNecessary(FlushEntityEvent event, Boolean mightBeDirty) +51
   NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event) +140
   NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event) +277
   NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) +167
   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +49
   NHibernate.Impl.SessionImpl.Flush() +96
   NHibernate.Transaction.AdoTransaction.Commit() +105
   N2.Persistence.NH.NHTransaction.Commit() in c:\ProjectsExtern\N2\N2-\src\N2\Persistence\NH\NHTransaction.cs:26
   N2.Persistence.NH.ContentPersister.Save(ContentItem unsavedItem) in c:\ProjectsExtern\N2\N2-\src\N2\Persistence\NH\ContentPersister.cs:99
   N2.Serialization.Importer.Import(IImportRecord record, ContentItem destination, ImportOption options) in c:\ProjectsExtern\N2\N2-\src\N2\Serialization\Importer.cs:75
   N2.Edit.Export.Default.Import(Importer importer, IImportRecord record) in c:\ProjectsExtern\N2\N2-\src\wwwroot\Edit\Export\Default.aspx.cs:136
   N2.Edit.Export.Default.btnImportUploaded_Click(Object sender, EventArgs e) in c:\ProjectsExtern\N2\N2-\src\wwwroot\Edit\Export\Default.aspx.cs:120
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Sep 23, 2008 at 5:32 PM
I think the problem is that one node is committed before the referenced is. If not for that circular references would work. I'll look into it.
Nov 5, 2008 at 8:25 PM
Was a solution found? I am getting this error now.
Nov 5, 2008 at 8:34 PM
Do you see this when the page contains links to uploaded documents? Do you have the file folder in the node tree? In that case this might be a bug that was fixed with (released as compiled runtime)
May 7, 2009 at 12:35 PM
Did this issue ever get resolved, I have run into the same problem and am wondering whether to update to the latest revision or write a fix.

The issue is the same outlined by maqdev.  The error occurs when I try to import content items excluding the root page of the import.  

I was thinking that when you use edit/install to import a full tree of content items this error never happens, I will investigate how this import code differs from the import code that is ran via the Export & Import items page. 

Any advice/help would be appreciated
May 7, 2009 at 9:48 PM
Possibly if it's related to the link tracker and links to files in the node-based file system (files and folders in the edit tree)
Sep 21, 2009 at 10:48 AM

is there any more information on this?


I'm stuck with the same error. 

Sep 22, 2009 at 9:31 PM

Are you using mysql? It's a bit hard without a reliable repro.