{"action":"created","issue":{"url":"https://api.github.com/repos/n2cms/n2cms/issues/689","labels_url":"https://api.github.com/repos/n2cms/n2cms/issues/689/labels{/name}","comments_url":"https://api.github.com/repos/n2cms/n2cms/issues/689/comments","events_url":"https://api.github.com/repos/n2cms/n2cms/issues/689/events","html_url":"https://github.com/n2cms/n2cms/issues/689","id":117211473,"number":689,"title":"NHibernate TransientObjectException when [WithEditableChild] used with a part that has an [EditableChildren] detail","user":{"login":"laurachan","id":3029296,"avatar_url":"https://avatars.githubusercontent.com/u/3029296?v=3","gravatar_id":"","url":"https://api.github.com/users/laurachan","html_url":"https://github.com/laurachan","followers_url":"https://api.github.com/users/laurachan/followers","following_url":"https://api.github.com/users/laurachan/following{/other_user}","gists_url":"https://api.github.com/users/laurachan/gists{/gist_id}","starred_url":"https://api.github.com/users/laurachan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laurachan/subscriptions","organizations_url":"https://api.github.com/users/laurachan/orgs","repos_url":"https://api.github.com/users/laurachan/repos","events_url":"https://api.github.com/users/laurachan/events{/privacy}","received_events_url":"https://api.github.com/users/laurachan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"libardo","id":153667,"avatar_url":"https://avatars.githubusercontent.com/u/153667?v=3","gravatar_id":"","url":"https://api.github.com/users/libardo","html_url":"https://github.com/libardo","followers_url":"https://api.github.com/users/libardo/followers","following_url":"https://api.github.com/users/libardo/following{/other_user}","gists_url":"https://api.github.com/users/libardo/gists{/gist_id}","starred_url":"https://api.github.com/users/libardo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libardo/subscriptions","organizations_url":"https://api.github.com/users/libardo/orgs","repos_url":"https://api.github.com/users/libardo/repos","events_url":"https://api.github.com/users/libardo/events{/privacy}","received_events_url":"https://api.github.com/users/libardo/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2015-11-16T20:32:39Z","updated_at":"2015-11-17T20:03:50Z","closed_at":null,"body":"I have a page model that has a child part added using the [WithEditableChild] attribute, as the example below illustrates:\r\n```\r\n    [PageDefinition(Description = \"...\")]\r\n    // Bunch of TabContainers \r\n    [WithEditableChild(typeof(ItemList), \"ItemList\", 1, ContainerName = \"ItemsTab\")]\r\n    public class ExamplePage : ContentPage \r\n    {\r\n        // Details omitted\r\n    }\r\n```\r\nThe child part contains an [EditableChildren] detail:\r\n```\r\n    [PartDefinition(\"Item List\")]\r\n    [AvailableZone(\"Items\", \"Items\")]\r\n    [RestrictParents(typeof(ExamplePage))]\r\n    [RestrictChildren(typeof(Item))]\r\n    [RestrictCardinality(MaximumCount = 1)]\r\n    public class ItemList : PartModelBase\r\n    {\r\n        [EditableChildren(\"Items\", \"Items\", 1)]\r\n        public virtual IEnumerable<Item> Items { get; set; }\r\n    }\r\n\r\n    [PartDefinition(\"Item\")]\r\n    [RestrictParents(typeof(ItemList))]\r\n    [AllowedZones(\"Items\")]\r\n    public class Item : PartModelBase\r\n    {\r\n        // Details omitted\r\n    }\r\n```\r\n\r\nIf I follow these steps, the child part causes an NHibernate exception. This scenario has caused some irritation for our content people when they tested one of our real pages that follows this pattern.\r\n1. Add a new ExamplePage, but only fill in some of the basic details. Do not switch to ItemsTab and add any items to the item list child part.\r\n2. Save and publish the page.\r\n3. Go back to edit details and makes some changes to the basic details only (i.e.: still not adding any items to the item list).\r\n4. Trying to save and publish results in an exception like the one below:\r\n\r\n```\r\n[TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: N2.ContentItem, Entity: ItemList {ItemList#0}]\r\n   NHibernate.Engine.ForeignKeys.GetEntityIdentifierIfNotUnsaved(String entityName, Object entity, ISessionImplementor session) +255\r\n   NHibernate.Type.ManyToOneType.Disassemble(Object value, ISessionImplementor session, Object owner) +85\r\n   NHibernate.Collection.Generic.PersistentGenericBag`1.Disassemble(ICollectionPersister persister) +147\r\n   NHibernate.Action.CollectionUpdateAction.<get_AfterTransactionCompletionProcess>b__0(Boolean success) +159\r\n   NHibernate.Engine.AfterTransactionCompletionProcessQueue.AfterTransactionCompletion(Boolean success) +83\r\n\r\n[AssertionFailure: Unable to perform AfterTransactionCompletion callback]\r\n   NHibernate.Engine.AfterTransactionCompletionProcessQueue.AfterTransactionCompletion(Boolean success) +262\r\n   NHibernate.Impl.SessionImpl.AfterTransactionCompletion(Boolean success, ITransaction tx) +363\r\n   NHibernate.Transaction.AdoTransaction.AfterTransactionCompletion(Boolean successful) +247\r\n   NHibernate.Transaction.AdoTransaction.Commit() +361\r\n\r\n[TransactionException: Commit failed with SQL exception]\r\n   NHibernate.Transaction.AdoTransaction.Commit() +534\r\n   N2.Persistence.NH.NHTransaction.Commit() in c:\\Work\\github\\n2cms\\src\\Framework\\N2\\Persistence\\NH\\NHTransaction.cs:53\r\n   N2.Edit.Workflow.CommandDispatcher.Execute(CommandBase`1 command, CommandContext context) in c:\\Work\\github\\n2cms\\src\\Framework\\N2\\Edit\\Workflow\\CommandDispatcher.cs:52\r\n   N2.Edit.Workflow.CommandDispatcher.Publish(CommandContext context) in c:\\Work\\github\\n2cms\\src\\Framework\\N2\\Edit\\Workflow\\CommandDispatcher.cs:65\r\n   N2.Edit.Edit.OnPublishCommand(Object sender, CommandEventArgs e) in C:\\Work\\github\\n2cms\\src\\Mvc\\MvcTemplates\\N2\\Content\\Edit.aspx.cs:128\r\n   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +111\r\n   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156\r\n   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10\r\n   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13\r\n   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9665034\r\n   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724\r\n```"},"comment":{"url":"https://api.github.com/repos/n2cms/n2cms/issues/comments/157489797","html_url":"https://github.com/n2cms/n2cms/issues/689#issuecomment-157489797","issue_url":"https://api.github.com/repos/n2cms/n2cms/issues/689","id":157489797,"user":{"login":"libardo","id":153667,"avatar_url":"https://avatars.githubusercontent.com/u/153667?v=3","gravatar_id":"","url":"https://api.github.com/users/libardo","html_url":"https://github.com/libardo","followers_url":"https://api.github.com/users/libardo/followers","following_url":"https://api.github.com/users/libardo/following{/other_user}","gists_url":"https://api.github.com/users/libardo/gists{/gist_id}","starred_url":"https://api.github.com/users/libardo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libardo/subscriptions","organizations_url":"https://api.github.com/users/libardo/orgs","repos_url":"https://api.github.com/users/libardo/repos","events_url":"https://api.github.com/users/libardo/events{/privacy}","received_events_url":"https://api.github.com/users/libardo/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T20:03:50Z","updated_at":"2015-11-17T20:03:50Z","body":"Great repro!"}}