-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Error:Cannot Insert. Insert fails.
PostPosted: Mon Jun 15, 2009 6:31 am 
Newbie

Joined: Mon Jun 15, 2009 3:32 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: Error:Cannot Insert. Insert fails.
PostPosted: Mon Jun 15, 2009 8:27 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hibernate normally first inserts the item and the updates the item with the foreign key. Check here for alternatives:

http://nhforge.org/doc/nh/en/index.html#example-parentchild

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.