Another test I tried:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="NHibernateTesting.Model.Order, NHibernateTesting"
lazy="false" table="Orders">
    <id name="Id" column="Id" type="int">
      <generator class="native" />
    </id>
    <version name="RowVersion" column="RowVersion" type="int" unsaved-
value="0" />
    <property name="Name" column="Name" type="string" />
    <property name="Total" column="Total" type="Decimal" />
  </class>
</hibernate-mapping>

Initial data, inserted with NDBUnit

 <Orders>
    <Id>1</Id>
    <Name>Test</Name>
    <Total>10.0</Total>
    <RowVersion>2</RowVersion>
  </Orders>

Then try an update and set rowversion to older:

var order = this.session.Get<Order>(1);

order.RowVersion = 1;
order.Name = "Test";

session.Update(order);


I would expect this to fail (I guess I have this totally wrong), if I
set genrated="never" on the version it will fail but obviously rely on
DB to increment. It will increment the version to 3 and save happily,
I can see in the log it states incrementing from 2 to 3, where is it
getting this 2 from? I assume some cache? If I evict the object it
will work fine showing that it is caching something. Please slap me
straight :P



Cheers



On Oct 1, 3:25 pm, codemonkey <[EMAIL PROTECTED]> wrote:
> It seems that If I evict my object out of the session it works, why
> would this be the case? I am selecting first so my child collections
> are not lost and I can map across the values from my DTO, this worked
> fine with a TimeStamp version column don't see why the integer is
> different maybe becuase the int is incremented by NH?
>
> On Oct 1, 2:23 pm, codemonkey <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > I recently changed all my RowVersion columns to use an integer instead
> > of the timestamp I was using, my optimistic locking was working
> > previously and the error would be thrown if I opened up the same
> > record and edited one, then edited the same version.
>
> > My service method firsts selects the record maps across from my DTO
> > and updates, no data acess code has changed just the RowVersion column
> > has changed. Any ideas would be great this is driving me nuts:
>
> >  public void Update(CourseUpdateDTO courseDTO) {
>
> >             // Load the existing course.
> >             var course =
> > this.courseRepository.SelectById(courseDTO.Id);
>
> >             // Map properties across.
> >             course.CricosCode = courseDTO.CricosCode;
> >             course.Description = courseDTO.Description;
> >             course.InternalCode = courseDTO.InternalCode;
> >             course.Title = courseDTO.Title;
> >             course.RowVersion = courseDTO.RowVersion;
>
> >             // Validate the model and update using the repository.
> >             course.Validate();
> >             this.courseRepository.Update(course);
>
> >         }
>
> > Mapping:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
> >   <class name="Course" table="Courses" lazy="false">
> >     <id name="Id" column="ID" type="int">
> >       <generator class="native" />
> >     </id>
> >     <version name="RowVersion" column="RowVersion" unsaved-value="0" /
>
> >     <many-to-one name="Institution" column="InstitutionID"
> > cascade="none" not-null="true" fetch="join" />
> >     <many-to-one name="SubjectArea" column="SubjectAreaID"
> > cascade="none" not-null="true" fetch="join" />
> >     <property name="Title" column="Title" type="string" />
> >     <property name="CricosCode" column="CRICOSCode" type="string" />
> >     <property name="InternalCode" column="InternalCode" type="string" /
>
> >     <property name="Description" column="Description" type="string" /
>
> >     <set name="CourseSemesters" inverse="true" lazy="true"
> > cascade="delete-orphan">
> >       <key column="CourseID" />
> >       <one-to-many
> > class="Phoenix.Link2Uni.ApplicationManager.Model.CourseSemester,Phoenix.Lin 
> > k2Uni.ApplicationManager.Model" /
>
> >     </set>
> >   </class>
> > </hibernate-mapping>
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to