In your version mapping, specify the unsaved-value attribute and set it to
0, like so:
Version(x => x.Version).SetAttribute("unsaved-value","0")
This should really be on the version part as a default, as well as allowing
you an optional override for a value. I'll add that to the VersionPart.
In general, the problem's an NHibernate problem though, not specifically
Fluent. You should have an unsaved-value specified on a version element.
On Tue, Apr 14, 2009 at 11:24 AM, depaulo <[email protected]>wrote:
>
> Hi
> When I try mapping the following model and inserting an OpenProject I
> get this error. If I make Project non-abstract it works. Anyone got
> any ideas?
>
> NHibernate.StaleObjectStateException: Row was updated or deleted by
> another transaction (or unsaved-value mapping was incorrect):
> [FluentNHib.Core.Domain.ClosedProject#b827aa8f-cea7-4b1a-a88b-
> eff845d56861]
>
> at NHibernate.Persister.Entity.AbstractEntityPersister.Check(Int32
> rows, Object id, Int32 tableNumber, IExpectation expectation,
> IDbCommand statement)
> at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
> id, Object[] fields, Object[] oldFields, Object rowId, Boolean[]
> includeProperty, Int32 j, Object oldVersion, Object obj,
> SqlCommandInfo sql, ISessionImplementor session)
> at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert
> (Object id, Object[] fields, Object[] oldFields, Object rowId, 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, Object rowId,
> ISessionImplementor session)
> at NHibernate.Action.EntityUpdateAction.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.PerformExecutions
> (IEventSource session)
> at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
> (FlushEvent event)
> at NHibernate.Impl.SessionImpl.Flush()
>
>
> DOMAIN OBJECTS:
>
> public class EntityBase
> {
> protected EntityBase()
> {
> ID = Guid.NewGuid();
> }
>
> public virtual Guid ID { get; set;}
> public virtual int Version { get; set; }
> }
>
>
> public abstract class Project : EntityBase
> {
> }
>
> public class OpenProject : Project
> {
> }
>
> MAPPING CLASSES:
>
> public abstract class MappingBase<T> : ClassMap<T> where T :
> EntityBase
> {
> protected MappingBase()
> {
> Id(e => e.ID).GeneratedBy.Assigned();
> Version(x => x.Version);
> }
> }
>
> public class ProjectMap : MappingBase<Project>
> {
> public ProjectMap()
> {
> DiscriminateSubClassesOnColumn("ProjectType")
> .SubClass<OpenProject>(MapOpenProject);
> }
>
> private void MapOpenProject(SubClassPart<string, Project,
> OpenProject> obj)
> {
> }
> }
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---