我正在学习HIBERNATE,今天在学习的悲观锁的时候,发现怎么锁失效了呢?具体如下:
Item是个实体,里面属性有Id,name,quantity.它的映射文件如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.hibernate">
<class name="Item" table="tb_item">
<id name="id">
 <generator class="native"/>
</id>
<property name="name"/>
<property name="quantity"/>
</class>hibernatte的配置文件如下:<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">168165</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<mapping resource="com/hibernate/Item.hbm.xml"/> </session-factory>
</hibernate-configuration>数据表里我已经插入一记录:1,脑白金,1000
当我取数据时,使用的语句为:Item im1 = (Item)session.load(Item.class, 2,LockMode.UPGRADE);
照道理,执行这个语句时候,立即生成如下的SQL语句:
Hibernate: select item0_.id as id0_0_, item0_.name as name0_0_, item0_.quantity as quantity0_0_ from tb_item item0_ where item0_.id=?for Update但是,结果是:Hibernate: select item0_.id as id0_0_, item0_.name as name0_0_, item0_.quantity as quantity0_0_ from tb_item item0_ where item0_.id=?
结果根本没加锁?
各位大虾帮帮忙,是哪里出错了?配置还是什么啊。哦,我用的是SQLserver2005数据库
拜托了,谢谢