waterye

          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();

          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=?

          參考:
          1. Hibernate Reference Documentation
          2. Hibernate API Documentation
          3. Hibernate Test Source

          posted on 2006-01-18 11:49 waterye 閱讀(2068) 評論(0)  編輯  收藏 所屬分類: hibernate

          主站蜘蛛池模板: 康乐县| 淮安市| 乌拉特前旗| 兴隆县| 堆龙德庆县| 关岭| 宜州市| 乌拉特后旗| 江津市| 武鸣县| 北辰区| 北川| 彩票| 延川县| 子长县| 合江县| 栾川县| 浦城县| 城市| 永登县| 获嘉县| 连山| 红原县| 永嘉县| 剑阁县| 福建省| 云南省| 威海市| 民乐县| 新巴尔虎左旗| 泰安市| 砚山县| 鞍山市| 贺州市| 凉山| 新巴尔虎右旗| 大足县| 延津县| 县级市| 凤庆县| 溆浦县|