Hi,

We use version 5.0.1. We spuriously get 'Constraint Violations' on the primary key of our root entity (once on 23 September and today).

Here's the definition of the base entity:

using System;
using System.Collections.Generic;
using Xtensive.Orm;

namespace Common.DataObjects.Library
{
    public abstract partial class DOEntity: Entity
    {
        /// <summary>
        /// Is de entity een nieuwe entity?
        /// </summary>
        public bool IsNew
        {
            get
            {
                return base.PersistenceState == Xtensive.Orm.PersistenceState.New;
            }
        }

        /// <summary>
        /// Dit is de bewaarde key van deze entity.
        /// Wanneer een entity verwijderd is kan niets meer worden gelezen van de entity (resulteert in een InvalidOperationException('Entity is removed');
        /// </summary>
        public long SavedId { get; set; }

        private List<Exception> m_Exceptions;

        /// <summary>
        /// Verzameling van exceptions die op deze entity plaats vonden
        /// </summary>
        public List<Exception> Exceptions
        {
            get
            {
                if(m_Exceptions == null)
                {
                    m_Exceptions = new List<Exception>();
                }

                return m_Exceptions;
            }
        }
    }
}

Here's the MesRoot entity:

using Common.DataObjects.Library;
using Common.Library;
using Common.Library.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xtensive.Orm;

namespace Fortrus.Model.Entities.Messaging
{
    /// <summary>
    /// Deze entity wordt door de meeste entities geerft. Daardoor is er maar 
    /// 1 HierarchyRoot entity en dat heeft tot gevolg dat elke Id in de gehele
    /// database (projecten schema) uniek is.
    /// </summary>
    [HierarchyRoot, KeyGenerator(Name = "MesRoot")]
    [TableMapping("MesRoot")]
    public partial class MesRootEntity : DOEntity, IId
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public MesRootEntity()
        {
        }

        // START partial class
        #region DataObjectsFields

        /// <summary>
        /// De key van de rootentity.
        /// </summary>
        [Key]
        [Field(Nullable = false), FieldMapping("Id")]
        public long Id { get; private set; }

        /// <summary>
        /// Who made the last change?
        /// Let op dit is het Control IT User id!
        /// </summary>
        [Field(Nullable = true)]
        public long? LastChangeBy { get; private set; }

        /// <summary>
        /// When was the row created?
        /// </summary>
        [Field(Nullable = true)]
        public DateTime? Created { get; private set; }

        #endregion //END region DataObjectsFields

        /// <summary>
        /// Is een machine user actief?
        /// </summary>
        public bool IsMachineUser
        {
            get
            {
                return LastChangeBy == (int)UserId.EnumUserId.Machine;
            }
        }

        partial void Initialize()
        {
            if (IsNew)
            {
                Created = DateTime.Now;
            }
        }

        /// <summary>
        /// De entity wordt verwijderd. Unhook alle events.
        /// </summary>
        protected override void OnRemove()
        {
            base.OnRemove();
        }

        /// <summary>
        /// Er is een veld van waarde veranderd. Zet de UserId die de wijziging uitvoerde.
        /// </summary>
        protected override object AdjustFieldValue(Xtensive.Orm.Model.FieldInfo field, object oldValue, object newValue)
        {
            if (field.Name != "LastChangeBy")
            {
                LastChangeBy = CommonInformation.UserId;
            }

            return base.AdjustFieldValue(field, oldValue, newValue);
        }

        /// <summary>
        /// De entity wordt verwijderd.
        /// </summary>
        partial void Removing()
        {
            LastChangeBy = CommonInformation.UserId;
        }

        /// <summary>
        /// Roep de Create aan op een static type
        /// </summary>
        public static TEntity Create<TEntity>()
        {
            Type type = typeof(TEntity);

            TEntity entity = (TEntity)type.InvokeMember("Create", System.Reflection.BindingFlags.Static, null, null, null);

            return entity;
        }
    }
}

Here's the exception:

Xtensive.Orm.UniqueConstraintViolationException
Fout Bericht:
SQL error occured. Storage error details 'Entity: MesRootEntity;' SQL error details 'Type: UniqueConstraintViolation; Table: MesRoot; Value: (25993); Constraint: PK_MesRootEntity;' Query 'INSERT INTO [Controlit].[Messaging].[MesRoot] ([Id], [TypeId], [LastChangeBy], [Created]) VALUES (@p1_0, @p1_1, @p1_2, @p1_3); INSERT INTO [Controlit].[Messaging].[Message] ([Id], [TypeId], [Recipient], [Sender], [Subject], [Body], [AttachmentName], [Host], [Port], [Result]) VALUES (@p1_0, @p1_1, @p1_4, @p1_5, @p1_6, @p1_7, @p1_8, @p1_9, @p1_10, @p1_11); [p1_0='25993';p1_1='154';p1_2='0';p1_3='25-11-2014 09:45:56';p1_4='d.wagenmakers@fortrus.nl';p1_5='noreply@fortrus.nl';p1_6='MID: 260378 'Recipient' is niet ingevuld voor uitvoerderId:1752';p1_7='Uitvoerder niet ingelicht. 'recipient' is niet ingevuld. Schema: 'RegulierSpoed', message type 'Mail', uitvoerderid: 1752. at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo) at System.Environment.get_StackTrace() at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.InformeerUitvoerderVolgensMeldschemaCommand.InformeerApplicatieBeheerder(Int32 uitvoerderid, MeldschemaType schematype, NotifcationAction action) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.InformeerUitvoerderVolgensMeldschemaCommand.WarnOnErrors(Int32 uitvoerderid, MeldschemaType schematype, NotifcationAction[] actions) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.InformeerUitvoerderVolgensMeldschemaCommand.NotificeerVolgensMeldschema(Int32 uitvoerderid, MeldschemaType schematype, Notitie notitie, IEnumerable`1 templates) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.InformeerUitvoerderVolgensMeldschemaCommand.InformeerHerstellerVolgensMeldschema(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.InformeerUitvoerderVolgensMeldschemaCommand.ExecuteInternal(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.ServiceCommand.Execute(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.MaakNotitieCommand.InformeerUitvoerder(Int64 notitieId) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.MaakNotitieCommand.UitvoerderInstellenEnInformeren(Int64 notitieId) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.MaakNotitieCommand.MaakNotitie() at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.MaakNotitieCommand.ExecuteInternal(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.ServiceCommand.Execute(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.MeldingMakenCommand.CreateNotitie(Int64 meldingId) at Fortrus.Intranet.Services.ServiceCommands.Controlit.Meldingen.MeldingMakenCommand.ExecuteInternal(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.ServiceCommand.Execute(IServiceContext context) at Fortrus.Intranet.Services.ServiceCommands.ServiceCommand.ExecuteCommandInNewContext() at Fortrus.Intranet.Services.ServiceCommands.ServiceCommand.ExecuteCommandInNewContextWithRetryOnDeadLock(Int32 maximumNumberOfRetries) at Fortrus.Intranet.Services.ServiceCommands.ServiceCommand.Execute() at Fortrus.Intranet.WebApplication.Controlit.Meldingen.Create.MeldingOpPandMaken() at Fortrus.Intranet.WebApplication.Controlit.Meldingen.Create.NotitieOpslaan() at Fortrus.Intranet.WebApplication.Controlit.Meldingen.Create.ButtonOpslaanClick(Object sender, EventArgs e) at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.controlit_meldingen_create_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)';p1_8='';p1_9='MAILSERVER';p1_10='25';p1_11='Ok']' Original message 'Violation of PRIMARY KEY constraint 'PK_MesRootEntity'. Cannot insert duplicate key in object 'Messaging.MesRoot'. The duplicate key value is (25993). String or binary data would be truncated. The statement has been terminated. The statement has been terminated.'

asked Nov 25 '14 at 04:00

Paul%20Sinnema's gravatar image

Paul Sinnema
261888896


One Answer:

Hi Paul

Looks strange. We'll check it.

answered Dec 08 '14 at 01:32

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA