I have a test on "optimistic-lock" attribute with component's property and found that it affects the version to be updated even though I set it to "false".
Anyone could tell the reason?
Thanks for your help.
Hibernate version: 1.2.1.4000
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model" assembly="Model">
<class name="Person" table="Person" dynamic-update="true" >
<id name="Id" column="ID" type="Int32">
<generator class="native" />
</id>
<timestamp name="Version" column="Version" />
<property name="Name" type="String" length="20" not-null="false" optimistic-lock="false" />
<component name="Info" class="Info">
<property name="Age" column="Age" type="Int32" not-null="false" optimistic-lock="false" />
<property name="Address" column="Address" type="String" length="50" not-null="false" optimistic-lock="false" />
</component>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Console.WriteLine("//save");
Person person = new Person();
person.Name = "personA";
person.Info.Age = 21;
person.Info.Address = "Home";
_session.Save(person);
_session.Flush();
System.Threading.Thread.Sleep(2000);
Console.WriteLine("//update");
person.Info.Age = 23;
_session.Flush();
Console.WriteLine("//delete");
_session.Delete(person);
_session.Flush();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MSSQL 2000
The generated SQL (show_sql=true):
//save
NHibernate: INSERT INTO Person (Version, Name, Age, Address) VALUES (@p0, @p1, @p2, @p3); select SCOPE_IDENTITY(); @p0 = '2008-5-1 12:42:03', @p1 = 'personA', @p2 = '21', @p3 = 'Home'
//update
NHibernate: UPDATE Person SET Version = @p0, Age = @p1, Address = @p2 WHERE ID = @p3 AND Version = @p4; @p0 = '2008-5-1 12:42:05', @p1 = '23', @p2 = 'Home', @p3 = '4', @p4 = '2008-5-1 12:42:03'
//delete
NHibernate: DELETE FROM Person WHERE ID = @p0 AND Version = @p1; @p0 = '4', @p1 = '2008-5-1 12:42:05'
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html