-->
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.  [ 1 post ] 
Author Message
 Post subject: optimistic-lock in component setting to false never affect
PostPosted: Thu May 01, 2008 12:53 am 
Newbie

Joined: Mon Mar 31, 2008 11:35 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.