日期:2014-05-18  浏览次数:20705 次

hibernate 乐观锁问题
我在学习乐观锁时,出现下面得exception:
22:43:03,046   ERROR   XMLHelper:61   -   Error   parsing   XML:   XML   InputStream(14)   组件“class”在此不允许“version”。

配置如下:
<?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.beans "   default-cascade= "save-update ">
    <class   name= "TUser "   table= "TUser "   optimistic-lock= "version ">
        <id   name= "id "   column= "id "   type= "long "   unsaved-value= "null ">
            <generator   class= "native "   />
        </id>
<property   name= "name "   column= "name "   />

<version     column= "version "   name= "version "   />

<set   name= "groups "   cascade= "all "   lazy= "true "   inverse= "true ">
            <key   column= "user_id "/>
            <one-to-many   class= "TGroup "/>
        </set>
    </class>
</hibernate-mapping>

测试方法:
private   void   lock(){
Session   session   =   getSession();
Transaction   tx   =   session.beginTransaction();
TUser   user   =   (TUser)session.get(TUser.class,new   Long(4));
user.setName( "this   is   a   test7 ");
session.saveOrUpdate(user);
tx.commit();
session.close();

}


麻烦各位大虾给点意见,先谢了!

------解决方案--------------------
version只能紧跟着id吧,即不太清了,还是好好看看文档吧。