Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > Session.evict(Object object), Session.setReadOnly(Object entity, boolean readOnly)
【标  题】:Session.evict(Object object), Session.setReadOnly(Object entity, boolean readOnly)
【关键字】:Session.evict,Object,object,Session.setReadOnly,Object,entity,boolean,readOnly
【来  源】:http://www.blogjava.net/waterye/archive/2006/01/18/28454.html

Session.evict(Object object), Session.setReadOnly(Object entity, boolean readOnly)

Your Ad Here BlogJava - Water鐨勫蹇樺綍 - Session.evict(Object object), Session.setReadOnly(Object entity, boolean readOnly)

Session.evict(Object object), Session.setReadOnly(Object entity, boolean readOnly)

public void evict(Object object) throws HibernateException
    Remove this instance from the session cache.
    Changes to the instance will not be synchronized with the database.
    This operation cascades to associated instances if the association is mapped with cascade="evict".

Test Case
hbm.xml
<class name="Customer" table="CUSTOMER" dynamic-insert="true" dynamic-update="true">

    
<id name="id">
        
<generator class="hilo"/>
    
</id>
    
    
<property name="code" not-null="true" length="50" />
    
<property name="name" not-null="true" length="200" />
    
<property name="status" length="20" />

</class>
Java code
Session s = openSession();
Transaction t 
= s.beginTransaction();

Customer c 
= (Customer) s.get(Customer.classnew Long(1));
s.evict(c);

c.setName(
"IBM");

t.commit();
s.close();
show sql
Hibernate: select customer0_.id as id0_0_, customer0_.code as code0_0_, customer0_.name as name0_0_, customer0_.status as status0_0_ from CUSTOMER customer0_ where customer0_.id=?

public void setReadOnly(Object entity, boolean readOnly)
    Set an unmodified persistent object to read only mode, or a read only object to modifiable mode.
    In read only mode, no snapshot is maintained and the instance is never dirty checked.

Test Case
Java code
Session s = openSession();
Transaction t 
= s.beginTransaction();

testCreate();

Customer c 
= (Customer) s.get(Customer.classnew Long(1)); 
s.setReadOnly(c, 
true);

c.setName(
"IBM");

t.commit();
s.close();
show sql
Hibernate: select customer0_.id as id0_0_, customer0_.code as code0_0_, customer0_.name as name0_0_, customer0_.status as status0_0_ from CUSTOMER customer0_ where customer0_.id=?

鍙傝?/STRONG>:
1. Hibernate Reference Documentation
2. Hibernate API Documentation
3. Hibernate Test Source

posted on 2006-01-18 11:49 Water Ye 闃呰(5) 璇勮(0)  缂栬緫 鏀惰棌 鏀惰棌鑷?65Key 鎵灞炲垎绫? hibernate

【相关评论】
没有相关评论
【发表评论】
姓名:
邮件:
随机码*
评论*
      
|  首 页  |  版权声明  |  联系我们   |  网站地图  |
CopyRight © 2004-2007 软讯网络 All Rigths Reserved.