hibernate中锁的问题
我使用是sql2000的数据库Session session=null;
try{
session=HibernateUitil.getSession();
session.beginTransaction();
Product p=(Product)session.load(Product.class,1,LockMode.UPGRADE);

System.out.println(p.getName());
System.out.println(p.getPrice());

p.setPrice(p.getPrice()-200);
session.update(p);

session.getTransaction().commit();

}catch(Exception e){
e.printStackTrace();
session.getTransaction().rollback();
}finally{
HibernateUitil.closeSession(session);
}
代码是上面的用load方法加的锁,测试的时候 数据没有被加上锁, 请问是怎么回事,用mysql这样写hibernate 会发一个有 for update的语句, 但用sql2000数据库时候  hibernate 不会发带有for update 语句  请各位大侠们指点

解决方案 »

  1.   

    不太懂
    LockMode.UPGRADE是什么意思
      

  2.   

    mysql跟sqlserver的锁本来就不同,我一直觉得sqlserver本来就是没有锁的概念在里面,例如,你在数据库里面插入一条数据,他就会直接插入,而没有事务,所以我觉得sqlserver锁模式跟mysql不同,具体可能要上网找找资料了。
      

  3.   

    sqlserver2000里没有select ... for update, 不过它有 select ... from TABLE as ALIAS with (updlock, rowlock) where ...
    如果你没有生成with updlock,那么说明你的SQL方言没有设定好:
    hibernate.dialect : org.hibernate.dialect.SQLServerDialect
      

  4.   

    我 SQL方言是设的  org.hibernate.dialect.SQLServerDialect 
      

  5.   

    那就是hibernate版本问题了,国外网站好像有人提过with加不上是个bug.