COU-620 - Processing relations will result in an SqlCeException: A duplicate value cannot be inserted into a unique index.

Created by Shannon Deminick 05 Sep 2017, 03:23:53 Updated by Warren Buckley 05 Sep 2017, 09:47:10

Subtask of: COU-521

The exception that occurs is:

NHibernate.Exceptions.GenericADOException occurred
  HResult=0x80131600
  Message=could not insert: [Umbraco.Courier.Persistence.V6.NHibernate.EntityClasses.UmbracoRelation][SQL: INSERT INTO umbracoRelation (comment, datetime, parentId, childId, relType) VALUES (?, ?, ?, ?, ?)]
  Source=NHibernate
  StackTrace:
   at NHibernate.Id.Insert.AbstractSelectingDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
   at NHibernate.Action.EntityIdentityInsertAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.Save(Object obj)
   at Umbraco.Courier.Persistence.V6.NHibernate.Persisters.RelationItem.PersistItem(Relation item) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Core\Umbraco.Courier.Persistence.V6.NHibernate\Persisters\RelationItem.cs:line 86
   at Umbraco.Courier.Core.ItemCrud`1.PersistItem[T1](T1 item) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Core\Umbraco.Courier.Core\ItemCrud.cs:line 48
   at Umbraco.Courier.Core.ItemCrudProvider.PersistItem[T](T item) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Core\Umbraco.Courier.Core\ProviderModel\Providers\ItemCrudProvider.cs:line 111
   at Umbraco.Courier.ItemProviders.ContentItemProvider`2.HandleItemPostProcess(T item) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Core\Umbraco.Courier.Providers\ItemProviders\ContentItemProvider.cs:line 91
   at Umbraco.Courier.Core.GenericItemProvider`1.HandlePostProcess(Item item) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Core\Umbraco.Courier.Core\ProviderModel\Providers\ItemProvider\GenericItemProvider.cs:line 86
   at Umbraco.Courier.Core.ItemProvider.PostProcess(Item item) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Core\Umbraco.Courier.Core\ProviderModel\Providers\ItemProvider\ItemProvider.cs:line 461
   at Umbraco.Courier.RepositoryProviders.Local.PostProcess(Item item, Boolean overwrite) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Contrib\Providers\Umbraco.Courier.RepositoryProviders\Local\Local.cs:line 132
   at Umbraco.Courier.RepositoryProviders.Webservices.Repository.PostProcessItems(String sessionKey, SerializedItemWrapper[] items, Boolean overWrite) in C:\Users\Shannon\Documents\_Projects\Umbraco\Courier_3\Contrib\Providers\Umbraco.Courier.RepositoryProviders\Webservices\Repository.asmx.cs:line 390

Inner Exception 1:
SqlCeException: A duplicate value cannot be inserted into a unique index. [ Table name = umbracoRelation,Constraint name = IX_umbracoRelation_parentChildType ]

Comments

Shannon Deminick 05 Sep 2017, 03:28:06

The problem is that NHibernate collections need to be populated accordingly. In this case when a relation was being created, it wasn't added to the parent or child nodes' relation collections.

PR: https://github.com/umbraco/Umbraco-Courier/pull/111


Warren Buckley 05 Sep 2017, 09:46:56

Thanks @Shandem Tested with the customers project and it worked fine :)


Priority: Normal

Type: Bug

State: Fixed

Assignee:

Difficulty:

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 3.1.5

Sprint: Sprint 67

Story Points: 1

Cycle: