I want to insert a record into a table named WorkMgmtPlanLineItems. But it fails and displays the following inner exception.
{"Cannot insert the value NULL into column 'WorkMgmtPlanID',
table 'C20PatchDev.dbo.WorkMgmtPlanLineItems'; column does not allow nulls.
INSERT fails.\r\nThe statement has been terminated."}
the function that i am executing is as follows:
public void AddTask(WorkMgmtPlanLineItems oWorkMgmtPlanLineItems) { ITransaction tx = null; try { if (!session.IsConnected) { session.Reconnect(); }
oWorkMgmtPlanLineItems.WorkMgmtPlanID = 112; oWorkMgmtPlanLineItems.TaskSerialNo = 113; oWorkMgmtPlanLineItems.OutlineLevel = 14; oWorkMgmtPlanLineItems.IsActive = true; oWorkMgmtPlanLineItems.IsMailSentFlag = true; oWorkMgmtPlanLineItems.IsLeafTask = true; oWorkMgmtPlanLineItems.IsProcessTask = true; oWorkMgmtPlanLineItems.IsSystemTask = true; oWorkMgmtPlanLineItems.IsActualsUploaded = true; oWorkMgmtPlanLineItems.IsMilestone = true; oWorkMgmtPlanLineItems.WBSID = DateTime.Now.ToString();
tx = session.BeginTransaction();
session.Save(oWorkMgmtPlanLineItems); session.Flush(); Console.WriteLine("\nTask with LineItem ID: " + oWorkMgmtPlanLineItems.LineItemID + " succefully added into database"); tx.Commit();
} catch (Exception ex) { //tx.Rollback(); session.Clear(); session.Disconnect(); throw ex.InnerException; // handle exception } }
The following is the mapping information for the table WorkMgmtPlanLineItems:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping namespace="C20Util.BusinessObjects" xmlns="urn:nhibernate-mapping-2.2" > <class name="C20Util.BusinessObjects.WorkMgmtPlanLineItems, C20Util" table="WorkMgmtPlanLineItems"> <jcs-cache usage="read-write" /> <id name="LineItemID" column="LineItemID" type="int" length="8" > <generator class="native"/> </id> <property name="WorkMgmtPlanID" insert="false" update="false" /> <property name="TaskSerialNo"/> <property name="ParentPlanLineItemID"/> <property name="ProcessDisciplineID"/> <property name="PCPhaseID"/> <property name="PCWorkFlowID"/> <property name="PCTaskID"/> <property name="WBSID"/> <property name="OutlineLevel"/> <property name="TaskName"/> <property name="ModuleID"/> <property name="SubModuleID"/> <property name="ProgramID"/> <property name="ReleaseID"/> <property name="IterationID"/> <property name="PlannedDuration"/> <property name="PlannedEffort"/> <property name="ScheduledDuration"/> <property name="ScheduledEffort"/> <property name="ActualDuration"/> <property name="ActualEffort"/> <property name="PerformedRoleID"/> <property name="CurrentStatusID" insert="false" update="false"/> <property name="IsMailSentFlag"/> <property name="IsLeafTask"/> <property name="IsProcessTask"/> <property name="IsSystemTask"/> <property name="IsActualsUploaded"/> <property name="IsMilestone"/> <property name="IsActive"/> <property name="RemainingEffort"/> <property name="LastUpdatedBy"/> <property name="Priority"/> <property name="Comments"/> <property name="IsUnplanned"/> <property name="ProcessPackageId"/> <property name="CreatedBy"/> <property name="Severity"/> <property name="PCWorkTypeID"/> <property name="WorkTypeStatusID"/> <property name="IsWorkRequestlevelTracking"/>
<many-to-one name="ForStatusDesc" class="C20Util.BusinessObjects.Status, C20Util" column="CurrentStatusID" cascade="none" unique="true"/>
<many-to-one name="ForMappedPlanIDs" class="C20Util.BusinessObjects.WorkMgmtPlan, C20Util" column="WorkMgmtPlanID" cascade="none" unique="true"/> </class> </hibernate-mapping>
The stack trace information:
at
NHibernate.Id.
Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
\r\n
at NHibernate.Persister.Entity.
AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)\r\n
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)\r\n
at NHibernate.Action.EntityIdentityInsertAction.Execute()\r\n at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)\r\n
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)\r\n
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)\r\n
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)\r\n
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)\r\n at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)\r\n
THis error occurs soon after the the session.save line gets executed the above mentioned function. Please provide me a solution to this problem.
|