-->
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.  [ 4 posts ] 
Author Message
 Post subject: Parent Child Problem
PostPosted: Thu Nov 29, 2007 10:42 am 
Newbie

Joined: Sun Nov 18, 2007 3:22 am
Posts: 8
Hi,
I am implementing mapping of parent-child.
i am trying to insert a parent and one child.
For some reason the Sql that is generated is trying to update the Row for the child instead of inserting one.
here is the code,mapping,usage and db declaration.

db:
Parent table:
CREATE TABLE [dbo].[PID_SnapshotLocation](
[SnapShotID] [int] IDENTITY(1,1) NOT NULL,
[LocationID] [int] NOT NULL,[SnapShotDate] [datetime] NOT NULL,
CONSTRAINT [PK_PID_SnapshotLocation] PRIMARY KEY CLUSTERED
([SnapShotID] ASC)) ON [PRIMARY]

child table:

CREATE TABLE [dbo].[PID_SnapshotItems](
[SnapShotID] [int] NOT NULL,[ItemID] [int] NOT NULL,
[Quantity] [real] NOT NULL
CONSTRAINT [PK_PID_SnapshotItems] PRIMARY KEY CLUSTERED
([ItemID] ASC)) ON [PRIMARY]

ALTER TABLE [dbo].[PID_SnapshotItems] WITH CHECK ADD CONSTRAINT [FK_PID_SnapshotItems_PID_SnapshotLocation] FOREIGN KEY([SnapShotID])
REFERENCES [dbo].[PID_SnapshotLocation] ([SnapShotID])

ALTER TABLE [dbo].[PID_SnapshotItems] CHECK CONSTRAINT [FK_PID_SnapshotItems_PID_SnapshotLocation]

mapping:
parent:

<class name="SnapShotLocation" table="PID_SnapshotLocation">
<id name="SnapShotID">
<generator class="native" />
</id>
<property name="LocationID"/>
<property name="SnapShotDate" type="DateTime"/>
<bag name="Items" inverse="true" cascade="all" optimistic-lock="false">
<key>
<column name="SnapShotID"/>
</key>
<one-to-many class="SnapShotItem"/>
</bag>
</class>

child:

<class name="SnapShotItem" table="PID_SnapshotItems">
<id name="ItemID">
<generator class="assigned" />
</id>
<many-to-one name="SnapShotID" class="SnapShotLocation" column="SnapShotID" cascade="all"/>
<property name="ItemQuantity" column="Quantity" type="double"/>
<property name="CountDate" column="InvCountDate" type="DateTime"/>
<property name="CountAmount" column="InvCountQuantity" type="Double"/>
<property name="ItemCost" type="Double"/>
</class>

code:
parent:
private int m_iLocationID;
private int m_iSnapShotID;
private DateTime m_dtSnapShotDate;
private IList<SnapShotItem> m_sItems = new List<SnapShotItem>();

public SnapShotLocation() { }
public SnapShotLocation(int LocationID, DateTime SnapShotDate)
{
m_iLocationID = LocationID;
m_dtSnapShotDate = SnapShotDate;
}
public virtual void AddItem(SnapShotItem ssi)
{
m_sItems.Add(ssi);
}
public virtual IList<SnapShotItem> Items { get { return m_sItems; } set { m_sItems = value; } }
public virtual int LocationID { get { return m_iLocationID; } set { m_iLocationID = value; } }
public virtual int SnapShotID { get { return m_iSnapShotID; } set { m_iSnapShotID = value; } }
public virtual DateTime SnapShotDate { get { return m_dtSnapShotDate; } set { m_dtSnapShotDate = value; } }

child:
private SnapShotLocation m_sSnapShotLocation;
private int m_iItemID;
private double m_iItemQuantity;
private DateTime m_dtInvCountDate;
private double m_dInvCountQuantity;
private double m_dItemCost;

public SnapShotItem() { }
public SnapShotItem(int ItemID,double ItemQ,DateTime InvCountD,double InvCountAmount,double ItemCost)
{
m_iItemID = ItemID;
m_iItemQuantity= ItemQ;
m_dtInvCountDate = InvCountD;
m_dInvCountQuantity = InvCountAmount;
m_dItemCost = ItemCost;
}

public virtual double ItemQuantity { get { return m_iItemQuantity; } set { m_iItemQuantity = value; } }
public virtual DateTime CountDate { get { return m_dtInvCountDate; } set { m_dtInvCountDate = value; } }
public virtual double CountAmount { get { return m_dInvCountQuantity; } set { m_dInvCountQuantity = value; } }
public virtual int ItemID { get { return m_iItemID; } set { m_iItemID = value; } }
public virtual SnapShotLocation SnapShotID { get { return m_sSnapShotLocation; } set { m_sSnapShotLocation = value; } }
public virtual double ItemCost { get { return m_dItemCost; } set { m_dItemCost = value; } }


usage:
using (ISession session = NHibernateHelper.GetCurrentSession(context))
{
using (ITransaction tx = session.BeginTransaction())
{
SnapShotLocation ssl = new SnapShotLocation(1, DateTime.Now);
SnapShotItem ssi = new SnapShotItem(1, 1, DateTime.Now, 1, 1);
ssi.SnapShotID = ssl;
ssl.AddItem(ssi);
session.SaveOrUpdate(ssl);
tx.Commit();
}}

The commit failes, i pasted the following from the log:


[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushEverything line(0):flushing session
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades CascadeCollection line(0):cascading to collection: Retalix.Dax.Applications.PInv.SnapShotLocation.Items
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass Cascade line(0):cascading to SaveOrUpdate()
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() persistent instance
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass Cascade line(0):cascading to SaveOrUpdate()
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() persistent instance
[2007-11-29 16:38:16](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushEntities line(0):Flushing entities and processing referenced collections
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.FlushVisitor ProcessCollection line(0):Processing collection for role Retalix.Dax.Applications.PInv.SnapShotLocation.Items
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl UpdateReachableCollection line(0):Collection found: [Retalix.Dax.Applications.PInv.SnapShotLocation.Items#15], was: [<unreferenced>]
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushEntity line(0):Updating entity: [Retalix.Dax.Applications.PInv.SnapShotItem#1]
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushCollections line(0):Processing unreferenced collections
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushCollections line(0):scheduling collection removes/(re)creates/updates
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushEverything line(0):Flushed: 0 insertions, 1 updates, 0 deletions to 2 objects
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl FlushEverything line(0):Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.Printer ToString line(0):listing entities:
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.Printer ToString line(0):Retalix.Dax.Applications.PInv.SnapShotItem{ItemQuantity=1, ItemID=1, ItemCost=1, CountDate=11/29/2007, CountAmount=1, SnapShotID=SnapShotLocation#15}
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.Printer ToString line(0):Retalix.Dax.Applications.PInv.SnapShotLocation{LocationID=1, Items=[SnapShotItem#1], SnapShotDate=11/29/2007, SnapShotID=15}
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.SessionImpl Execute line(0):executing flush
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.ConnectionManager FlushBeginning line(0):registering flush begin
[2007-11-29 16:38:16](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Update line(0):Updating entity: [Retalix.Dax.Applications.PInv.SnapShotItem#1]
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.BatcherImpl LogOpenPreparedCommand line(0):Opened new IDbCommand, open IDbCommands: 1
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.BatcherImpl Generate line(0):Building an IDbCommand object for the SqlString: UPDATE PID_SnapshotItems SET SnapShotID = ?, Quantity = ?, InvCountDate = ?, InvCountQuantity = ?, ItemCost = ? WHERE ItemID = ?
[2007-11-29 16:38:16](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Dehydrate line(0):Dehydrating entity: [Retalix.Dax.Applications.PInv.SnapShotItem#1]
[2007-11-29 16:38:16](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '15' to parameter: 0
[2007-11-29 16:38:16](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 1
[2007-11-29 16:38:16](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '11/29/2007' to parameter: 2
[2007-11-29 16:38:16](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 3
[2007-11-29 16:38:16](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 4
[2007-11-29 16:38:16](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 5
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.BatcherImpl LogCommand line(0):UPDATE PID_SnapshotItems SET SnapShotID = @p0, Quantity = @p1, InvCountDate = @p2, InvCountQuantity = @p3, ItemCost = @p4 WHERE ItemID = @p5; @p0 = '15', @p1 = '1', @p2 = '11/29/2007 4:38:13 PM', @p3 = '1', @p4 = '1', @p5 = '1'
[2007-11-29 16:38:16](DEBUG): NHibernate.Impl.BatcherImpl LogClosePreparedCommand line(0):Closed IDbCommand, open IDbCommands: 0
[2007-11-29 16:38:16](ERROR): NHibernate.Impl.SessionImpl Execute line(0):could not synchronize database state with session
NHibernate.StaleStateException: Unexpected row count: 0; expected: 1
at NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()

THX alot


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 2:26 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
The problem is that the cascade uses SaveOrUpdate to determine whether the children are transient (to be saved) or not (to be updated). SaveOrUpdate determines this using data that is set only at Save() time, either the identifier or a version counter. However, you have no version on your item, and the id is assigned. Since it can't figure it out, it defaults to Updating the row, which isn't actually there.

Either change the id generator class on SnapShotItem, or add a version property/column (see http://www.hibernate.org/hib_docs/nhibe ... on-version ).

(Edit: fix URL)


Last edited by marcal on Mon Dec 03, 2007 3:54 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Problem parent-child
PostPosted: Sun Dec 02, 2007 5:44 am 
Newbie

Joined: Sun Nov 18, 2007 3:22 am
Posts: 8
Hi Marcal,
Thx for the help but i couldnt make it work.
Inserting new items succeeded but it is not updating the exisitng ones.
Can u b more specific?
I did not understand from the link what should i change.
I added a coulmn to SnapShotItem table and add a property for it(INT)
But how should i init it or assign that column?

The row i added to mapping file is:
<version name="Version"/>
and in the code:
public virtual int Version { get { return m_iVersion; } set { m_iVersion = value; } }



[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl .ctor line(0):opened session
[2007-12-02 11:26:07](DEBUG): NHibernate.Transaction.AdoTransaction Begin line(0):begin
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+IdentifierValue IsUnsaved line(0):unsaved-value: 0
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() unsaved instance
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl DoSave line(0):saving [Retalix.Dax.Applications.PInv.SnapShotLocation#<null>]
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl ExecuteInserts line(0):executing insertions
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.WrapVisitor ProcessArrayOrNewCollection line(0):Wrapped collection in role: Retalix.Dax.Applications.PInv.SnapShotLocation.Items
[2007-12-02 11:26:07](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Insert line(0):Inserting entity: Retalix.Dax.Applications.PInv.SnapShotLocation (native id)
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.BatcherImpl LogOpenPreparedCommand line(0):Opened new IDbCommand, open IDbCommands: 1
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.BatcherImpl Generate line(0):Building an IDbCommand object for the SqlString: INSERT INTO PID_SnapshotLocation (LocationID, SnapShotDate) VALUES (?, ?); select SCOPE_IDENTITY()
[2007-12-02 11:26:07](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Dehydrate line(0):Dehydrating entity: [Retalix.Dax.Applications.PInv.SnapShotLocation#<null>]
[2007-12-02 11:26:07](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 0
[2007-12-02 11:26:07](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '12/2/2007' to parameter: 1
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.BatcherImpl LogCommand line(0):INSERT INTO PID_SnapshotLocation (LocationID, SnapShotDate) VALUES (@p0, @p1); select SCOPE_IDENTITY(); @p0 = '1', @p1 = '12/2/2007 11:26:07 AM'
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.BatcherImpl LogOpenReader line(0):Opened IDataReader, open IDataReaders: 1
[2007-12-02 11:26:07](DEBUG): NHibernate.Type.NullableType NullSafeGet line(0):returning '30' as column:
[2007-12-02 11:26:07](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister GetGeneratedIdentity line(0):Natively generated identity: 30
[2007-12-02 11:26:07](DEBUG): NHibernate.Driver.NHybridDataReader Dispose line(0):running NHybridDataReader.Dispose()
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.BatcherImpl LogCloseReader line(0):Closed IDataReader, open IDataReaders :0
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.BatcherImpl LogClosePreparedCommand line(0):Closed IDbCommand, open IDbCommands: 0
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades CascadeCollection line(0):cascading to collection: Retalix.Dax.Applications.PInv.SnapShotLocation.Items
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass Cascade line(0):cascading to SaveOrUpdate()
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+VersionValue IsUnsaved line(0):unsaved-value: 0
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() unsaved instance
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl SaveWithGeneratedIdentifier line(0):generated identifier: 2
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl DoSave line(0):saving [Retalix.Dax.Applications.PInv.SnapShotItem#2]
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass Cascade line(0):cascading to SaveOrUpdate()
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() persistent instance
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+VersionValue IsUnsaved line(0):unsaved-value: 0
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Versioning Seed line(0):Seeding: 1
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-12-02 11:26:07](DEBUG): NHibernate.Transaction.AdoTransaction Commit line(0):commit
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl FlushEverything line(0):flushing session
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades CascadeCollection line(0):cascading to collection: Retalix.Dax.Applications.PInv.SnapShotLocation.Items
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass Cascade line(0):cascading to SaveOrUpdate()
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() persistent instance
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotLocation
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades+CascadingAction+ActionSaveUpdateClass Cascade line(0):cascading to SaveOrUpdate()
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl SaveOrUpdate line(0):SaveOrUpdate() persistent instance
[2007-12-02 11:26:07](DEBUG): NHibernate.Engine.Cascades Cascade line(0):done processing cascades for: Retalix.Dax.Applications.PInv.SnapShotItem
[2007-12-02 11:26:07](DEBUG): NHibernate.Impl.SessionImpl FlushEntities line(0):Flushing entities and processing referenced collections
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.FlushVisitor ProcessCollection line(0):Processing collection for role Retalix.Dax.Applications.PInv.SnapShotLocation.Items
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.SessionImpl UpdateReachableCollection line(0):Collection found: [Retalix.Dax.Applications.PInv.SnapShotLocation.Items#30], was: [<unreferenced>]
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.SessionImpl FlushCollections line(0):Processing unreferenced collections
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.SessionImpl FlushCollections line(0):scheduling collection removes/(re)creates/updates
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.SessionImpl FlushEverything line(0):Flushed: 1 insertions, 0 updates, 0 deletions to 2 objects
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.SessionImpl FlushEverything line(0):Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.Printer ToString line(0):listing entities:
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.Printer ToString line(0):Retalix.Dax.Applications.PInv.SnapShotItem{Version=1, ItemQuantity=1, ItemID=2, ItemCost=1, CountDate=12/2/2007, CountAmount=1, SnapShotID=SnapShotLocation#30}
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.Printer ToString line(0):Retalix.Dax.Applications.PInv.SnapShotLocation{LocationID=1, Items=[SnapShotItem#2], SnapShotDate=12/2/2007, SnapShotID=30}
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.SessionImpl Execute line(0):executing flush
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.ConnectionManager FlushBeginning line(0):registering flush begin
[2007-12-02 11:26:08](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Insert line(0):Inserting entity: [Retalix.Dax.Applications.PInv.SnapShotItem#2]
[2007-12-02 11:26:08](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Insert line(0):Version: 1
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.BatcherImpl LogOpenPreparedCommand line(0):Opened new IDbCommand, open IDbCommands: 1
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.BatcherImpl Generate line(0):Building an IDbCommand object for the SqlString: INSERT INTO PID_SnapshotItems (Version, SnapShotID, Quantity, InvCountDate, InvCountQuantity, ItemCost, ItemID) VALUES (?, ?, ?, ?, ?, ?, ?)
[2007-12-02 11:26:08](DEBUG): NHibernate.Persister.Entity.AbstractEntityPersister Dehydrate line(0):Dehydrating entity: [Retalix.Dax.Applications.PInv.SnapShotItem#2]
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 0
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '30' to parameter: 1
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 2
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '12/2/2007' to parameter: 3
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 4
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '1' to parameter: 5
[2007-12-02 11:26:08](DEBUG): NHibernate.Type.NullableType NullSafeSet line(0):binding '2' to parameter: 6
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.BatcherImpl LogCommand line(0):INSERT INTO PID_SnapshotItems (Version, SnapShotID, Quantity, InvCountDate, InvCountQuantity, ItemCost, ItemID) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6); @p0 = '1', @p1 = '30', @p2 = '1', @p3 = '12/2/2007 11:26:07 AM', @p4 = '1', @p5 = '1', @p6 = '2'
[2007-12-02 11:26:08](DEBUG): NHibernate.Impl.BatcherImpl LogClosePreparedCommand line(0):Closed IDbCommand, open IDbCommands: 0
[2007-12-02 11:26:08](DEBUG): NHibernate.Util.ADOExceptionReporter LogExceptions line(0):could not insert: [Retalix.Dax.Applications.PInv.SnapShotItem#2] [INSERT INTO PID_SnapshotItems (Version, SnapShotID, Quantity, InvCountDate, InvCountQuantity, ItemCost, ItemID) VALUES (?, ?, ?, ?, ?, ?, ?)]
System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_PID_SnapshotItems'. Cannot insert duplicate key in object 'dbo.PID_SnapshotItems'.
The statement has been terminated.


Thx,
Tomer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 4:04 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
NH controls the version column, so you should never set it. Either map it directly to a field, or only expose a getter and use "nosetter" access of some kind.

I recall that there was some issue with the inital assigned version value confusing NH's unsaved-value. What version of NH are you using?

(BTW, I corrected the URL above if you want to take another look. Also see http://www.hibernate.org/hib_docs/nhibe ... ild-update which discusses this issue directly).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.