why not use a 'timestamp' type instead? A date/time field is never going to
work, as SQLServer stores it with a precision of 300ms, so every action on
the row within 300ms will look like it's ok, while it's not.
FB
> Okay, I figured out what the issue is, but still wondering what to do.
The
> table is defined with the SQL datatype of "smalldatetime", and therefore
> doesn't store the actual SECONDS portion of the time, but nHibernate
passes
> that in and therefore can't find the timestamp value.
>
> What do I do to tell nHibernate this is actually a smalldatetime instead
of
> a regular datetime?
>
> On Aug 24, 9:12 am, MattO <[email protected]> wrote:
> > I'm getting the following error when running the flush command after
> > trying to persist an object to the database. I've ran a SQL profiler
> > trace and I see what is wrong, but I don't know how to fix it.
> >
> > Basically nHibernate is inserting the record to the database properly,
> > but when it goes to retrieve the timestamp column it is unable to find
> > the record that was inserted due to the seconds part of the time being
> > chopped off and therefore can not retrieve the time part of the
> > timestamp.
> >
> > NHibernate: INSERT INTO [dbo].[ott_QuickLaunchResponses]
> > ([ReviewType], [FullKey], [UserAnswer], [AnsweredCorrectly],
> > [InitialPPlus], [TotalPPlus], [FinalPPlus], [Accept], [Replace],
> > [Revise], [Delete], [Reject], [Comment], [FormID], [RecordID],
> > [DateEntered], [Initials]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6,
> > @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16);@p0 = 85, @p1
> > = 'Test ', @p2 = 'Test T', @p3 = True, @p4 = 61, @p5 = 12, @p6 = 77,
> > @p7 = 0, @p8 = 0, @p9 = 0, @p10 = 0, @p11 = 0, @p12 = 'Test Test ',
> > @p13 = 38, @p14 = 4, @p15 = 8/24/2010 8:51:13 AM, @p16 = 'Test Test'
> >
> > We can see the record was inserted properly. nHibernate will now
> > refresh the timestamp property since optimistic locking is set to
> > "version" in the mapping file. This is where the error is. Notice
> > the select statement to retrieve the timestamp (TS column). What
> > happens at the database level when it is wrapped in an sp_executesql
> > statement the seconds portion of the datetime variable will get
> > chopped off and will therefore not find the timestamp value, and thus
> > the error "Unable to locate row for retrieval of generated properties"
> > error.
> >
> > NHibernate: SELECT quicklaunc_.TS as TS17_ FROM [dbo].
> > [ott_QuickLaunchResponses] quicklaunc_ WHERE quicklaunc_.[formi...@p0
> > and quicklaunc_.[recordi...@p1 and quicklaunc_.[dateentere...@p2 and
> > quicklaunc_.[initial...@p3;@p0 = 38, @p1 = 4, @p2 = 8/24/2010 8:51:13
> > AM, @p3 = 'Test Test'
> > Test 'ItemBankCoreNH.UnitTests.QuickLaunchResponseTests.Create'
> > failed: NHibernate.HibernateException : Unable to locate row for
> > retrieval of generated properties:
> > [ItemBankCoreNH.BusinessObjects.QuickLaunchResponse#ItemBankCoreNH.Bus
> > inessObjects.QuickLaunchResponse]
> > at
> > NHibernate.Persister.Entity.AbstractEntityPersister.ProcessGeneratedPr
> > operties(Object id, Object entity, Object[] state,
> > ISessionImplementor session, SqlString selectionSQL, ValueInclusion[]
> > includeds)
> > at
> > NHibernate.Persister.Entity.AbstractEntityPersister.ProcessInsertGener
> > atedProperties(Object id, Object entity, Object[] state,
> > ISessionImplementor session)
> > at NHibernate.Action.EntityInsertAction.Execute()
> > at NHibernate.Engine.ActionQueue.Execute(IExecutable
> > executable)
> > at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
> > at NHibernate.Engine.ActionQueue.ExecuteActions()
> > at
> > NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutio
> > ns(IEventSource
> > session)
> > at
> > NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
> > event)
> > at NHibernate.Impl.SessionImpl.Flush()
> > Base\ManagerBase.cs(209,0): at
> > ItemBankCoreNH.Base.ManagerBase`2.Flush()
> > UnitTests\QuickLaunchResponseTests.cs(69,0): at
> > ItemBankCoreNH.UnitTests.QuickLaunchResponseTests.Create()
> >
> > Heres a snippet of the HBM file:
> >
> > <class name="ItemBankCoreNH.BusinessObjects.QuickLaunchResponse,
> > ItemBankCoreNH" table="[dbo].[ott_QuickLaunchResponses]"
> > optimistic-lock="version" dynamic-update="true"
> > lazy="true">
> > <composite-id>
> > <key-property name="FormID" column="[FormID]" />
> > <key-property name="RecordID" column="[RecordID]" />
> > <key-property name="DateEntered" column="[DateEntered]" />
> > <key-property name="Initials" column="[Initials]" />
> > </composite-id>
> > <version name="TS" generated="always" unsaved-value="null"
> > type="BinaryBlob">
> > <!-- Generated="always" is to have database handle
> > generation of timestamp -->
> > <column name="TS" not-null="false" sql-type="timestamp"/>
> > </version>
> > <property name="ReviewType" column="[ReviewType]" />
> > <property name="FullKey" column="[FullKey]" />
> >
> > I have no idea how to fix this.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.